Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 22168 | Accepted: 9104 | Special Judge |
Description
Input
Output
Sample Input
2 6 19 0
Sample Output
10 100100100100100100 111111111111111111Source
题意
刚看到数据时候把我吓到了,一想是不是要用大数,要用数组存呢?
然后看了一下 讨论 ,顿时感觉自己被骗了..用数据不会超过long long的.
以后要自己先尝试一下,防止出现类似情况
#include<iostream> // 5080K 547MS #include<cstdio> #include<cstring> #include<queue> #include<algorithm> #include<queue> using namespace std; queue<long long> Q; int n; long long p; int BFS() { while(!Q.empty()) //否则会MLE Q.pop(); Q.push(1); while(!Q.empty()) { p=Q.front(); Q.pop(); for(int i=0;i<2;i++) { if(p%n==0) { printf("%lld\n",p); return 1; } if(i==0) Q.push(p*10); if(i==1) Q.push(p*10+1); } } return 0; } int main() { while(~scanf("%d",&n),n) { BFS(); } }
//704K 157Ms
#include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> using namespace std; bool found; void DFS( long long sum ,int n,int k) { if(k==19) //防止爆<span id="transmark"></span> return ; if(found) //找到了就停止其他递归 return ; if(sum%n==0) { printf("%lld\n",sum); found=true; return ; } DFS(sum*10,n,k+1); DFS(sum*10+1,n,k+1); } int main() { int n; while(~scanf("%d",&n),n) { found=false; DFS(1,n,0); } return 0; }