zoukankan      html  css  js  c++  java
  • 51 nod 1109 01组成的N的倍数

    基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
     收藏
     关注
    给定一个自然数N,找出一个M,使得M > 0且M是N的倍数,并且M的10进制表示只包含0或1。求最小的M。
     
    例如:N = 4,M = 100。
    Input
    输入1个数N。(1 <= N <= 10^6)
    Output
    输出符合条件的最小的M。
    Input示例
    4
    Output示例
    100
    思路:同上题。
    #include<queue>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct nond{
        string s;
        int mod;
    }cur,net;
    queue<nond>que;
    int n;
    bool vis[1000001];
    int main(){
        scanf("%d",&n);
        cur.s="1";cur.mod=1;
        que.push(cur);
        while(!que.empty()){
            cur=que.front();
            que.pop();
            net.mod=(cur.mod*10)%n;
            net.s=cur.s+'0';
            if(net.mod==0){
                cout<<net.s;
                return 0;
            }
            if(!vis[net.mod]){
                que.push(net);
                vis[net.mod]=1;
            }
            net.mod=(cur.mod*10+1)%n;
            net.s=cur.s+'1';
            if(net.mod==0){
                cout<<net.s;
                return 0;
            }
            if(!vis[net.mod]){
                que.push(net);
                vis[net.mod]=1;
            }
        }
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    (copy) Shell Script to Check Linux System Health
    HTML5 笔记1
    成年后更想要人懂
    端午不过节
    兜兜转转还是往前了一小步
    五月下旬这些天
    立陶宛话剧观后感
    杯子
    你学过的东西总会在某个时候用到
    初识理财记
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/7502242.html
Copyright © 2011-2022 走看看