标签:wal include retrieve while teleport art dia enter size
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2717
Catch That Cow
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14880 Accepted Submission(s): 4495
1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 using namespace std; 5 int v[100010],t[100010]; 6 int main() 7 { 8 int n,a,b,i,f; 9 while(scanf("%d%d",&a,&b)!=EOF) 10 { 11 memset(t,0,sizeof(t)); 12 memset(v,0,sizeof(v)); 13 queue<int > q; 14 q.push(a); 15 v[a]=1; 16 if(a==b) 17 { 18 printf("0\n"); 19 continue; 20 } 21 while(!q.empty()) 22 { 23 int ll=q.front(),r=ll-1,l=ll+1,z=ll*2; 24 q.pop(); 25 //printf("ll=%d\n",ll); 26 if(z>=0&&z<=100000&&!v[z]) 27 { 28 q.push(z); 29 v[z]=v[ll]+1; 30 // printf("v[z]=%d z=%d\n",v[z],z); 31 } 32 if(l>=0&&l<=100000&&!v[l]) 33 { 34 q.push(l); 35 v[l]=v[ll]+1; 36 // printf("v[l]=%d l=%d\n",v[l],l); 37 } 38 if(r>=0&&r<=100000&&!v[r]) 39 { 40 q.push(r); 41 v[r]=v[ll]+1; 42 // printf("v[r]=%d r=%d\n",v[r],r); 43 } 44 45 if(l==b||r==b||z==b) 46 { 47 48 break; 49 } 50 51 } 52 53 printf("%d\n",v[b]-1); 54 55 } 56 return 0; 57 58 }
HDU2717-Catch That Cow (BFS入门)
标签:wal include retrieve while teleport art dia enter size
原文地址:http://www.cnblogs.com/ljmzzyk/p/6896780.html