标签:amp return namespace 边界条件 front style empty span scanf
还是很简单的水题。不过他的边界条件我到现在还是不是很懂hhhh
#include <cstdio> #include <queue> #include <cstring> using namespace std; struct position { int x; int min; }; queue <position> q; int vis[100001]; int main() { position man, temp; int start, end; while(~scanf("%d%d", &start, &end)) { memset(vis, 0, sizeof(vis)); while(!q.empty()) q.pop(); man.x = start; man.min = 0; q.push(man); vis[man.x]=1; while(!q.empty()) { man = q.front(); q.pop(); if(man.x == end) { printf("%d\n", man.min); break; } temp.x = man.x+1; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) { temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); } temp.x = man.x-1; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) { temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); } temp.x = man.x*2; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) { temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); } } } return 0; }
标签:amp return namespace 边界条件 front style empty span scanf
原文地址:https://www.cnblogs.com/Vikyanite/p/11382478.html