Description
Input
Output
Sample Input
2 6 19 0
Sample Output
10 100100100100100100 111111111111111111
沒有仔細分析題目,我一看最后的output不會超過100位,我就在想怎么存呢
想了好久也沒想出好方法,如果數組存的話,可能會超內存,判斷也可能會超時,最后現不到好辦法
我還想要不要用double存,然后只是判斷麻煩一些而以,
結果去網上找題解發現,只要longlong就能出正解
呃……我是沙茶
還有隊列開了好大,要定義成全局變量
1#include<stdio.h> 2#include<string.h> 3#include<math.h> 4int n; 5long long now,q[1000000]; 6void bfs() 7{ 8 int head,tail; 9 head=0;10 tail=1;11 q[tail]=1;12 while(head<tail)13 {14 head++;15 now=q[head];16 now=now*10;17 if(now%n==0)18 {19 break;20 }21 tail++;22 q[tail]=now;23 tail++;24 q[tail]=now+1;25 }26 printf("%I64d\n",now);27}28int main()29{30 while(scanf("%d",&n)!=EOF&&n!=0)31 {32 bfs();33 }34 return 0;35}36
posted on 2012-03-15 19:05 jh818012 閱讀(633) 評論(2) 編輯 收藏 引用
17 if(now%n==0)18 {19 break;20 }你這里判斷明顯慢了很多啊,在下面判斷now*10和now*10+1這樣要快很多。 回復 更多評論
我嚓,,輝哥,,居然搜到你的題解了 回復 更多評論
Powered by: C++博客 Copyright © jh818012