Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
啊啊啊 为什么自己测试的对却一直WA! 用的G++#include<stdio.h> #include<queue> #include<string.h> using namespace std; typedef struct Node {int x; int sum; }Node; int m,n; int flag[200000]; int BFS() {Node p,q; queue<Node> qu; p.x=m; p.sum=0; qu.push(p); while(!qu.empty()) { p=qu.front(); qu.pop(); if(m==n) return 0; if(p.x==n) return p.sum; p.sum++; q=p; q.x=q.x*2; if(q.x>=0&&q.x<=100000&&flag[q.x]){flag[q.x]=0; qu.push(q);} q=p; q.x--; if(q.x>=0&&q.x<=100000&&flag[q.x]) {flag[q.x]=0;qu.push(q);} q=p; q.x++; if(q.x>=0&&q.x<=100000&&flag[q.x]) { flag[q.x]=0; qu.push(q);} } } main() {int a; while(scanf("%d%d",&m,&n)!=EOF) {memset(flag,1,sizeof(flag)); a=BFS(); printf("%d\n",a);} return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator