标签:des style blog color java os io strong
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1075 Accepted Submission(s): 649
1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <algorithm> 5 #include <iostream> 6 #include <math.h> 7 #include <map> 8 using namespace std; 9 #define N 1000000 10 #define LL __int64 11 12 map<pair<int,int>,int>visited; 13 int X[N+2], Y[N+2]; //这里若改成map(int,int)X,Y提交后500多MS,可以看出当数据大的话map不如数组模拟hash匹配 14 15 void init(){ //打表奇异局势 16 double i, j, k, r=(sqrt(5)+1.0)/2.0; 17 int a, b; 18 for(i=0;i<=N;i++){ 19 a=i*r; 20 b=a+i; 21 if(b>N) break; 22 X[(int)i]=a; 23 Y[(int)i]=b; 24 } 25 } 26 27 main() 28 { 29 int a, b; 30 double j, k, r=(sqrt(5)+1.0)/2.0; 31 int i; 32 init(); 33 while(scanf("%d %d",&a,&b)==2&&(a||b)){ 34 visited.clear(); 35 k=b-a; 36 if(a==(int)(k*r)){ //当a和b满足奇异局势时必输 37 printf("0\n");continue; 38 } 39 printf("1\n"); 40 if(a-X[(int)k]==b-Y[(int)k]&&a-X[(int)k]>0&&b-Y[(int)k]>0){ //看同时从两堆物品中取相同数目的物品时能否达到奇异局势 41 printf("%d %d\n",X[(int)k],Y[(int)k]); 42 visited[make_pair(X[(int)k],Y[(int)k])]=1; 43 } 44 for(i=0;i<=N;i++){ //从1堆物品中取 45 if(a==X[i]&&visited.find(make_pair(X[i],Y[i]))==visited.end()){ 46 printf("%d %d\n",X[i],Y[i]); 47 // visited[make_pair(X[i],Y[i])]=1; 48 break; 49 } 50 if(a==Y[i]&&visited.find(make_pair(X[i],Y[i]))==visited.end()){ 51 printf("%d %d\n",X[i],Y[i]); 52 // visited[make_pair(X[i],Y[i])]=1; 53 break; 54 } 55 } 56 } 57 }
HDU 2177 威佐夫博奕 hdu1527升级版,布布扣,bubuko.com
标签:des style blog color java os io strong
原文地址:http://www.cnblogs.com/qq1012662902/p/3925419.html