poj - 1426-Find The Multiple-BFS

13 篇文章 0 订阅
6 篇文章 0 订阅

题意:

给你一个数n,让你找到一个由0,1构成的n的倍数

思路:

姿势对了,就过了

1.0

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
long long bfs(int n)
{
    queue<long long>p;
    while(!p.empty())
    {
        p.pop();
    }
    p.push(1);
    while(1)
    {
        long long sum = p.front();
        if(sum%n == 0)
            return sum;
        p.pop();
        p.push(10*sum);
        p.push(10*sum+1);
    }

}
int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        printf("%lld\n",bfs(n));
    }
    return 0;
}

2.0

转载

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#define mem(a) memset(a,0,sizeof(a))

using  namespace std;
string str[]={
    "0",
    "1",
"10",
"111",
"100",
"10",
"1110",
"1001",
"1000",
"111111111",
"10",
"11",
"11100",
"1001",
"10010",
"1110",
"10000",
"11101",
"1111111110",
"11001",
"100",
"10101",
"110",
"110101",
"111000",
"100",
"10010",
"1111111101",
"100100",
"1101101",
"1110",
"111011",
"100000",
"111111",
"111010",
"10010",
"11111111100",
"111",
"110010",
"10101",
"1000",
"11111",
"101010",
"1101101",
"1100",
"1111111110",
"1101010",
"10011",
"1110000",
"1100001",
"100",
"100011",
"100100",
"100011",
"11111111010",
"110",
"1001000",
"11001",
"11011010",
"11011111",
"11100",
"100101",
"1110110",
"1111011111",
"1000000",
"10010",
"1111110",
"1101011",
"1110100",
"11111001",
"10010",
"10011",
"111111111000",
"10001",
"1110",
"11100",
"1100100",
"1001",
"101010",
"11101001",
"10000",
"1111111101",
"111110",
"101011",
"1010100",
"111010",
"11011010",
"11010111",
"11000",
"11010101",
"1111111110",
"1001",
"11010100",
"10000011",
"100110",
"110010",
"11100000",
"11100001",
"11000010",
"111111111111111111",
"100",
"101",
"1000110",
"11100001",
"1001000",
"101010",
"1000110",
"110100111",
"111111110100",
"1111111011",
"110",
"111",
"10010000",
"1011011",
"110010",
"1101010",
"110110100",
"11111110101",
"110111110",
"110001101",
"111000",
"11011",
"1001010",
"10011100011",
"11101100",
"1000",
"11110111110",
"11010011",
"10000000",
"100100001",
"10010",
"101001",
"11111100",
"11101111",
"11010110",
"11111111010",
"11101000",
"10001",
"111110010",
"110110101",
"100100",
"10011",
"100110",
"1001",
"1111111110000",
"11011010",
"100010",
"1100001",
"11100",
"110111",
"11100",
"1110001",
"11001000",
"11111011011",
"10010",
"1110110",
"1010100",
"10101101011",
"111010010",
"100011",
"100000",
"11101111",
"11111111010",
"1010111",
"1111100",
"1111110",
"1010110",
"11111011",
"10101000",
"10111101",
"111010",
"1111011111",
"110110100",
"1111111011",
"110101110",
"100100",
"110000",
"101110011",
"110101010",
"11010111",
"11111111100",
"1001111",
"10010",
"100101",
"110101000",
"1110",
"100000110",
"1001011",
"1001100",
"1111111100001",
"110010",
"11101111",
"111000000",
"11001",
"111000010",
"101010",
"110000100",
"1101000101",
"1111111111111111110",
"111000011",
"1000",
"10010001",
"1010",
"11010111",
"10001100",
"111110",
"111000010",
"11101011111",
"10010000",
"100111",
"101010",
"110100011",
"10001100",
"10011",
"1101001110",
"11011010",
"1111111101000",
"10000011",
"11111110110",
"1110111",
"1100",
"100111011",
"1110",
"1001111001",
"100100000",
"11111111100",
"10110110",
"11001101",
"1100100",
"11110111101",
"1101010",
"111111",
"1101101000",
"111110011",
"111111101010",
"100110",
"1101111100",
"101010111",
"1100011010",
"1111111",
"1110000",
"111101",
"110110",
"111101101011",
"10010100",
"11000010",
"100111000110",
"1000000001",
"111011000",
"1111100001",
"1000",
"110001001",
"111101111100",
"11111001",
"110100110",
"1000110",
"100000000",
"101001",
"1001000010",
"10101",
"100100",
"11001111111",
"1010010",
"10001101",
"111111000",
"1000110",
"111011110",
"1101010011",
"110101100",
"100100011",
"11111111010",
"11111",
"111010000",
"10101",
"100010",
"1100",
"1111100100",
"110111101",
"1101101010",
"11111010111",
"1001000",
"101000111",
"100110",
"11010100001",
"1001100",
"110010",
"10010",
"1011101",
"11111111100000",
"1100110001",
"11011010",
"100110111",
"1000100",
"110000111",
"11000010",
"110111110",
"111000",
"1111111111111111011",
"1101110",
"10100100101",
"11100",
"1110001011",
"11100010"};

int main()
{
    int n;
    while(cin>>n,n!=0)
    {
        cout<<str[n]<<endl;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值