poj3278 Catch that cow 代码比很多人精简。。。BFS
2013-05-27 17:08
381 查看
在一条线上找羊,农夫可以向前或向后一步,还可以步数乘二的跳跃。 #include<iostream> #include<queue> #include<memory.h> #include<time.h> using namespace std; int Line[100001]; int N,K; queue<int> Q; int main() { clock_t start,end; cin>>N>>K; start=clock(); memset(Line,0, sizeof(Line)); Q.push(N); int at; while(!Q.empty()) { at=Q.front();Q.pop(); if(at==K) { cout<<Line[at]<<endl; break; } if((at-1)>=0&&Line[at-1]==0) { Q.push(at-1); Line[at-1]=Line[at]+1; } if((at+1)<=100000&&Line[at+1]==0) { Q.push(at+1); Line[at+1]=Line[at]+1; } if(2*at<=100000&&Line[at*2]==0) { Q.push(2*at); Line[at*2]=Line[at]+1; } } end=clock(); cout<<(end-start)<<endl; return 0; }
相关文章推荐
- poj3278 Catch That Cow(bfs搜索)
- POJ3278 Catch That Cow(bfs)
- POJ3278 Catch That Cow —— BFS
- Poj3278 Catch That Cow (BFS)
- poj3278 Catch That Cow(简单的一维bfs)
- POJ3278-Catch That Cow(bfs)
- POJ3278 Catch That Cow 【BFS】
- poj3278 Catch That Cow BFS
- POJ3278 Catch That Cow(BFS)
- 广度优先搜索bfs与抓住那头奶牛(Catch that cow, poj3278)
- POJ3278 Catch That Cow(BFS入门)
- Poj3278 Catch That Cow ( BFS
- poj3278 Catch That Cow bfs
- [bfs] poj3278 Catch that Cow
- poj3278 Catch That Cow BFS搜索 TWT Tokyo Olympic 2combo-1
- 【poj3278】Catch that cow——bfs
- poj3278-catch that cow(bfs广搜)
- POJ3278 Catch That Cow(BFS) 坑爹的RE
- poj3278 Catch That Cow(bfs java)
- 【搜索BFS】poj3278--Catch That Cow(bfs)