zoukankan      html  css  js  c++  java
  • poj1426 宽搜

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only 
    the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100
    decimal digits.

    考试的时候一看200位直接就被吓到了,直接跳过,后来听说答案开long long 可过,就是普通宽搜,感觉亏了一个亿,既然每一位不是0就是1,首先第一位一定是1,然后每次这个数乘10,或者乘10加1,就是可以产生每一位都是1或者0的数字了。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #define ll long long
     5 using namespace std;
     6 int n;
     7 queue<long long>q;
     8 ll ans;
     9 int main()
    10 {
    11     while(1)
    12     {
    13         cin>>n;
    14         if(!n)break;
    15         while(!q.empty())q.pop();
    16         q.push(1);
    17         while(!q.empty())
    18         {
    19             ll k=q.front();q.pop();
    20             if(k%n==0)
    21             {
    22                 ans=k;break;
    23             }
    24             q.push(k*10),q.push(k*10+1);
    25         }
    26         printf("%lld
    ",ans);
    27     }
    28 
    29     return 0;
    30 }
  • 相关阅读:
    区间DP入门
    Prime Permutation(思维好题 )
    小字辈 (bfs好题)
    博弈论小结之尼姆博弈
    Hometask
    Lucky Sum (dfs打表)
    对称博弈
    尼姆博弈
    莫队算法 ( MO's algorithm )
    Codeforces 988D Points and Powers of Two ( 思维 || 二的幂特点 )
  • 原文地址:https://www.cnblogs.com/yuelian/p/12565294.html
Copyright © 2011-2022 走看看