| ||||||||||
| 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 | |||||||||
真题出的真没意思。你好歹给点限制啊,随便输出一个,我随便输出一个你又给我错?//换long long 不然就会错
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define ll long long
int cnt = 0;
queue<ll>q;
void bfs(int n)
{
while(!q.empty()){
ll ptr = q.front(),p;
q.pop();
if(ptr % n == 0){
printf("%lld\n",ptr);
return ;
}
for(int i = 0;i < 2;i++){
if(i == 0){
p = ptr*10+1;
q.push(p);
}
else{
p = ptr*10;
q.push(p);
}
}
}
}
int main()
{
int n;
while(~scanf("%d",&n) && n){
while(!q.empty()){
q.pop();
}
q.push(1);
bfs(n);
}
return 0;
}
//害的我半天不敢下手,想出了4种转移状态,每一位变化1或者0,尾部+1或者尾部+0
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator