栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1153 Tournament Seeding

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1153 Tournament Seeding

#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define inf 0x3f3f3f3fusing namespace std;int match[130],play[130],t,n,r,tmp,i,j,cnt,m,x,rou,p1,p2,ans;int main(){    match[0]=1;    tmp=64;    r=2;    for(i=1;i<=7;i++)    {        for(j=0;j<128;j+= 2*tmp)        { match[j+tmp]=r+1-match[j];        }        r*=2;        tmp/=2;    }    for(i=0;i<128;i++)        play[match[i]]=i;    scanf("%d",&t);    while(t--)    {        cnt=0;        while(scanf("%d%d",&n,&m)&&(n||m))        { cnt++; tmp=n-1;r=0; while(tmp>0) {     tmp/=2;     r++; } x=1<<(7-r); ans=inf; for(i=1;i<=(m-1)/2;i++) {     if(i<=n&&(m-i)<=n)     {         rou=0;         tmp=x*2;         p1=play[i];         p2=play[m-i];         while(p1!=p2)         {  rou++;  p1=p1-(p1%tmp);  p2=p2-(p2%tmp);  tmp*=2;         }         if(ans>rou) ans=rou;     } } printf("Case %d: Round %dn",cnt,ans);        }        if(t) putchar('n');    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373661.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号