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

                          1,首先就是 (13%3=((1×10)%3+3)%3

                      用同余定理,如果a%n=c,b%n=c,a<b,那么这个时候b就不用入队了,因为答案只看余数(这是第一种剪枝,
                          2,另外一个剪枝就是相同的余数不必继续入队列
                          3,上代码了
                          4()
                          

    #include <algorithm>
    #include <stdio.h>
    #include <stack>
    #include <istream>
    #include <map>
    #include <math.h>
    #include <vector>
    #include <iostream>
    #include <queue>
    #include <string.h>
    #include <set>
    #include <cstdio>
    #define MAX 2005
    using namespace std;
    const int maxn = 20000007;
    int vis[maxn];
    struct cnm{
    vector <char> inof;
    int weishu;
    }temp,now;
    queue <cnm> lb;
    int main() {
    int n;
    scanf("%d", &n);
    if (n == 1) {
    printf("1 "); return 0;
    }
    bool ans = 1;
    memset(vis, 0, sizeof(vis));
    vis[1] = 1;
    now.weishu = 1;
    now.inof.push_back('1');
    lb.push(now);
    while (true) {
    now = lb.front(); lb.pop();
    int a = now.weishu * 10;
    for (int i = 0; i < 2; i++) {
    int b = (a + i) % n;
    if (vis[b])continue;
    if (b == 0) {
    for (int j = 0; j < now.inof.size(); j++) {
    printf("%c", now.inof[j]);
    }
    printf("%d ", i);
    ans = 0;
    }
    vis[b] = 1;
    temp = now;
    temp.inof.push_back(i+'0');
    temp.weishu = b;
    lb.push(temp);
    }
    if (!ans)break;
    }
    return 0;
    }

    我身后空无一人,我怎敢倒下
  • 相关阅读:
    Node.js NPM 包(Package)
    Node.js NPM 作用
    Node.js NPM 介绍
    Node.js NPM 教程
    Node.js NPM 教程
    Node.js 发送Email
    Node.js 上传文件
    Node.js 事件
    Node.js NPM
    Node.js 文件系统模块
  • 原文地址:https://www.cnblogs.com/DreamKill/p/8798193.html
Copyright © 2011-2022 走看看