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 |
为什么会RE呢???求指导啊#include <iostream> #include <stdio.h> #include <string.h> #include <queue> using namespace std; int i,j,n,k,minute,len[200000]; struct step { int place; int minute; }; step next,now; queue<step>q; void bfs(int n) { int dir[3]={-1,1,n}; now.place=n; now.minute=0; len[now.place]=0; while(!q.empty()) q.pop(); q.push(now); while(!q.empty()) { now=q.front(); q.pop(); if(now.place==k) { cout<<now.minute<<endl; break; } for(i=0;i<3;i++) { if(len[now.place+dir[i]]>0) continue; if(now.place+dir[i]<n) continue; next.place=now.place+dir[i]; next.minute=now.minute+1; len[next.place]=next.minute; q.push(next); } } } int main() { freopen("in.txt","r",stdin); while(cin>>n>>k) { memset(len,0,sizeof(len)); bfs(n); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator