poj 1426 Find The Multiple(bfs)
2016-12-07 12:55
375 查看
思路很简单,第一个数字为1,第一位以后的数字为0或1,往后不停的试,直到找到结果。
这题第一次提交时re,我就修改队列数组的大小,改了好几次,不re了,内存又超了,又改了一次,内存不超了,超时了,然后把c++的io换成c的,终于ac了。
这题第一次提交时re,我就修改队列数组的大小,改了好几次,不re了,内存又超了,又改了一次,内存不超了,超时了,然后把c++的io换成c的,终于ac了。
#include <cstdio> struct node { int digit; int remain; int hd; }; node que[800000]; int res[1000]; int main() { int n,flag; while(scanf("%d",&n) && n) { flag = 0; int head = 0, tail = 0; que[tail].hd = -1; que[tail].digit = 1; que[tail].remain = 1 % n; ++tail; while(head < tail) { node temp; for(int k = 0; k < 2; ++k) { temp.digit = k; temp.remain = (que[head].remain*10 + temp.digit) % n; temp.hd = head; que[tail++] = temp; if(temp.remain == 0) { flag = 1; break; } } if(flag) break; ++head; } int index = 0; for(int i = --tail; i != -1; i = que[i].hd) res[index++] = que[i].digit; for(int i = --index; i >= 0; --i) printf("%d",res[i]); printf("\n"); } return 0; }
相关文章推荐
- POJ1426-Find The Multiple (BFS 余数)
- poj 1426 Find The Multiple (bfs 搜索)
- POJ1426 Find The Multiple(bfs)
- DFS/BFS(同余模) POJ 1426 Find The Multiple
- poj 1426 Find The Multiple(bfs)
- poj 1426 Find The Multiple( bfs )
- POJ 1426 Find The Multiple (bfs搜索)
- poj - 1426-Find The Multiple-BFS
- poj 1426 Find The Multiple (BFS)
- POJ_1426_Find The Multiple(BFS)
- POJ 1426 Find The Multiple(BFS)
- poj 1426 Find The Multiple(bfs)
- POJ 1426-Find The Multiple(bfs)
- Poj 1426--Find The Multiple(bfs或dfs)
- POJ训练计划1426_Find The Multiple(BFS)
- Find The Multiple (poj 1426 bfs)
- POJ 1426 Find The Multiple(BFS 水~)
- POJ - 1426 Find The Multiple(15.10.10 搜索专题)bfs
- POJ 1426 Find The Multiple(简单搜索bfs)
- poj 1426 Find The Multiple special judge BFS or Doubi mode