题意:求n的一个倍数m,m的十进制表示的每一位要不为0,要么为1。(1 <= n <= 200)
题目链接:http://poj.org/problem?id=1426
——>>这题的数据可能不是那么的严,可以用long long水过。
寒假时bfs过
#include <iostream>
#include <queue>
using namespace std;
void bfs(int n, long long &s)
{
queue<long long> qu;
qu.push(1);
while(!qu.empty())
{
s = qu.front();
qu.pop();
if(!(s%n)) return;
else
{
qu.push(s*10);
qu.push(s*10+1);
}
}
while(!qu.empty())qu.pop();
}
int main()
{
int n;
while(cin>>n)
{
if(!n) return 0;
long long s;
bfs(n, s);
cout<<s<<endl;
}
}
今天暴搜过:
translate(x)将十进制数x的二进制表示以十进制数表示出来。
#include <cstdio>
using namespace std;
const int maxn = 100 + 10;
long long translate(int x)
{
int i, j, buf[maxn];
for(i = 0; x; i++)
{
buf[i] = x % 2;
x /= 2;
}
long long ret = 0;
for(j = i-1; j >= 0; j--) ret = ret * 10 + buf[j];
return ret;
}
int main()
{
int n, i;
long long temp;
while(scanf("%d", &n) == 1 && n)
{
for(i = 1; ; i++)
{
temp = translate(i);
if(temp % n == 0) break;
}
printf("%I64d\n", temp);
}
return 0;
}