hdu 4474 大整数取模+bfs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474
(a*10+b)%c = ((a%c)*10+b%c)%c;
然后从高位开始枚举能填的数字填充,只是注意最高位(第一位)不能为0。
代码:
- #include<cstdio>
- #include<iostream>
- #include<algorithm>
- #include<cstring>
- #include<string>
- #include<queue>
- using namespace std;
- struct Node
- {
- string s;
- int mod;
- Node(string s="",int mod=): s(s),mod(mod) {}
- };
- bool can[];
- bool vis[];
- string ans;
- bool bfs(int n)
- {
- queue<Node> Q;
- string temp = "";
- Q.push(Node(temp,));
- while(!Q.empty())
- {
- Node node = Q.front();
- Q.pop();
- if(node.mod == && node.s != "" && node.s!="")
- {
- ans = node.s;
- return true;
- }
- for(int i=; i<=; i++)
- {
- if(!can[i] ) continue;
- if(i == && node.s == "") continue;
- int mod = (node.mod* + i)%n;
- if(vis[mod]) continue;
- temp = node.s + char(i + '');
- vis[mod] = true;
- Q.push(Node(temp,mod));
- }
- }
- return false;
- }
- int main()
- {
- //freopen("E:\\acm\\input.txt","r",stdin);
- int n,m;
- int T = ;
- while(cin>>n>>m)
- {
- for(int i=; i<=; i++) can[i] = true;
- for(int i=; i<m; i++)
- {
- int a;
- scanf("%d",&a);
- can[a] = false;
- }
- ans = "";
- memset(vis,,sizeof(vis));
- printf("Case %d: ",++T);
- if(!bfs(n))
- printf("-1\n");
- else
- cout<<ans<<endl;
- }
- }
hdu 4474 大整数取模+bfs的更多相关文章
- poj2305-Basic remains(进制转换 + 大整数取模)
进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...
- cogs 2170. 大整数取模
2170. 大整数取模 ★ 输入文件:bigint.in 输出文件:bigint.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 输入正整数n和m,输出n mo ...
- HDU 5698 大组合数取模(逆元)
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- 【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】
3751: [NOIP2014]解方程 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4856 Solved: 983[Submit][Status ...
- Snowflake Snow Snowflakes(哈希,大素数取模)
Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27277 Accepted: 7197 Description You ...
- 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数
typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...
- HDU 1212 大整数的取模运算
因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...
- HDU 6211 卡常数取模 预处理 数论
求所有不超过1e9的 primitive Pythagorean triple中第2大的数取模$2^k$作为下标,对应a[i]数组的和. 先上WIKI:https://en.wikipedia.org ...
- lucas定理解决大组合数取模
LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...
随机推荐
- Cisco AnyConnect “Failed to initialize connection subsystem”的解决方案
Per Cisco: Microsoft has released a fix-it patch providing a workaround for this issue. See KB# 3023 ...
- js日期格式,日期对象
以对象为基准去使用方法, 围绕Date对象 var a = new Date() 返回当前的时间对象,可以使用内置的日期对象的方法 a.getFullYear(), a.getMonth(), a.g ...
- jquery插件,美化select标签
最近经常与select打交道,因为ie下的select实在太丑了,css怎么搞都搞不好看,因为程序已经写得差不多了,要再去模拟select改动太大,就想着能否不改动select,同时美化它.借鉴一下这 ...
- CMD 模块定义规范
在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范.该规范明确了模块的基本书写格式和基本交互规则. 在 CMD 规范 ...
- bzoj 3751: [NOIP2014]解方程 同余系枚举
3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...
- 为ant指定编译版本
用Eclipse的ant折腾了一天也没搞清楚为什么同样的设置ant出的class版本却不一样.后来下载个ant工具在命令行执行通过. 从网上抄得指定编译版本的方法如下: ant 运行时,必需依赖jdk ...
- C语言嵌入式系统编程修炼之四:屏幕操作
汉字处理 现在要解决的问题是,嵌入式系统中经常要使用的并非是完整的汉字库,往往只是需要提供数量有限的汉字供必要的显示功能.例如,一个微波炉的LCD上没有必要提供显示"电子邮件"的功 ...
- android实现json数据的解析和把数据转换成json格式的字符串
利用android sdk里面的 JSONObject和JSONArray把集合或者普通数据,转换成json格式的字符串 JSONObject和JSONArray解析json格式的字符串为集合或者一般 ...
- 14.8.9 Clustered and Secondary Indexes
14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...
- 【HDOJ】1930 And Now, a Remainder from Our Sponsor
简单字符串. #include <stdio.h> #define MAXLEN 160 char buf[MAXLEN]; ], parts[]; void getpart(int x) ...