题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474

(a*10+b)%c = ((a%c)*10+b%c)%c;

然后从高位开始枚举能填的数字填充,只是注意最高位(第一位)不能为0。

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<string>
  6. #include<queue>
  7. using namespace std;
  8.  
  9. struct Node
  10. {
  11. string s;
  12. int mod;
  13. Node(string s="",int mod=): s(s),mod(mod) {}
  14. };
  15.  
  16. bool can[];
  17. bool vis[];
  18. string ans;
  19.  
  20. bool bfs(int n)
  21. {
  22. queue<Node> Q;
  23.  
  24. string temp = "";
  25. Q.push(Node(temp,));
  26.  
  27. while(!Q.empty())
  28. {
  29. Node node = Q.front();
  30. Q.pop();
  31.  
  32. if(node.mod == && node.s != "" && node.s!="")
  33. {
  34. ans = node.s;
  35. return true;
  36. }
  37.  
  38. for(int i=; i<=; i++)
  39. {
  40. if(!can[i] ) continue;
  41. if(i == && node.s == "") continue;
  42. int mod = (node.mod* + i)%n;
  43. if(vis[mod]) continue;
  44.  
  45. temp = node.s + char(i + '');
  46. vis[mod] = true;
  47.  
  48. Q.push(Node(temp,mod));
  49. }
  50. }
  51. return false;
  52. }
  53.  
  54. int main()
  55. {
  56. //freopen("E:\\acm\\input.txt","r",stdin);
  57.  
  58. int n,m;
  59. int T = ;
  60. while(cin>>n>>m)
  61. {
  62. for(int i=; i<=; i++) can[i] = true;
  63. for(int i=; i<m; i++)
  64. {
  65. int a;
  66. scanf("%d",&a);
  67. can[a] = false;
  68. }
  69. ans = "";
  70. memset(vis,,sizeof(vis));
  71. printf("Case %d: ",++T);
  72.  
  73. if(!bfs(n))
  74. printf("-1\n");
  75. else
  76. cout<<ans<<endl;
  77. }
  78. }

hdu 4474 大整数取模+bfs的更多相关文章

  1. poj2305-Basic remains(进制转换 + 大整数取模)

    进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...

  2. cogs 2170. 大整数取模

    2170. 大整数取模 ★   输入文件:bigint.in   输出文件:bigint.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 输入正整数n和m,输出n mo ...

  3. HDU 5698 大组合数取模(逆元)

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  4. 【BZOJ】3751: [NOIP2014]解方程【秦九韶公式】【大整数取模技巧】

    3751: [NOIP2014]解方程 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4856  Solved: 983[Submit][Status ...

  5. Snowflake Snow Snowflakes(哈希,大素数取模)

    Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 27277   Accepted: 7197 Description You ...

  6. 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数

    typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...

  7. HDU 1212 大整数的取模运算

    因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...

  8. HDU 6211 卡常数取模 预处理 数论

    求所有不超过1e9的 primitive Pythagorean triple中第2大的数取模$2^k$作为下标,对应a[i]数组的和. 先上WIKI:https://en.wikipedia.org ...

  9. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...

随机推荐

  1. 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 ...

  2. js日期格式,日期对象

    以对象为基准去使用方法, 围绕Date对象 var a = new Date() 返回当前的时间对象,可以使用内置的日期对象的方法 a.getFullYear(), a.getMonth(), a.g ...

  3. jquery插件,美化select标签

    最近经常与select打交道,因为ie下的select实在太丑了,css怎么搞都搞不好看,因为程序已经写得差不多了,要再去模拟select改动太大,就想着能否不改动select,同时美化它.借鉴一下这 ...

  4. CMD 模块定义规范

    在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范.该规范明确了模块的基本书写格式和基本交互规则. 在 CMD 规范 ...

  5. bzoj 3751: [NOIP2014]解方程 同余系枚举

    3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...

  6. 为ant指定编译版本

    用Eclipse的ant折腾了一天也没搞清楚为什么同样的设置ant出的class版本却不一样.后来下载个ant工具在命令行执行通过. 从网上抄得指定编译版本的方法如下: ant 运行时,必需依赖jdk ...

  7. C语言嵌入式系统编程修炼之四:屏幕操作

    汉字处理 现在要解决的问题是,嵌入式系统中经常要使用的并非是完整的汉字库,往往只是需要提供数量有限的汉字供必要的显示功能.例如,一个微波炉的LCD上没有必要提供显示"电子邮件"的功 ...

  8. android实现json数据的解析和把数据转换成json格式的字符串

    利用android sdk里面的 JSONObject和JSONArray把集合或者普通数据,转换成json格式的字符串 JSONObject和JSONArray解析json格式的字符串为集合或者一般 ...

  9. 14.8.9 Clustered and Secondary Indexes

    14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...

  10. 【HDOJ】1930 And Now, a Remainder from Our Sponsor

    简单字符串. #include <stdio.h> #define MAXLEN 160 char buf[MAXLEN]; ], parts[]; void getpart(int x) ...