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\n"); 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\n", 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;
}

转载于:https://www.cnblogs.com/DreamKill/p/8798193.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值