题目链接: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的更多相关文章

  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. jquery 单引号和双引号的区别及使用注意

    在js中单引号和双引号都是一样的,平时使用的时候尽量用单引号,只有碰到嵌套的时候才会同时用两种引号,感兴趣的朋友可以了解下: 可以执行的语法:$("ul li a").filter ...

  2. linux rman shell

    # make direcory for backset file and scripts file,in my case /backup/db_bak cd   /backup/db_bak mkdi ...

  3. 阿里云服务器(Win 2008 R2 Standard)安装MSSM 2008 R2之1033和2052问题

    最近在给租用的阿里云服务器安装Sql Server 2008 R2 Express时,遭遇下面的问题.经过几番折腾后,终于解决问题,完成安装,这里总结分享我的解决方法,希望能给遇到相同问题的小伙伴们节 ...

  4. Zend Studio 11.0.2 破解和汉化

    本方法适用于Zend Studio 11.0.2,亲测,其他版本未知. 破解方法:覆盖安装目录 plugins 里同名文件,启动任意输入即可注册. Windows版下载地址:http://downlo ...

  5. winform下载网页源码

    public partial class Form1 : Form{public Form1(){InitializeComponent();} private void button1_Click( ...

  6. 日期相关---SimpleDateFormat的setLenient(true/false)-----自动计算日期

    有时候我们需要判断用户的日期格式是否正确, 虽然绝大多数会在前台处理,但是也有需要从文件流读入的情况,如果日期不合格就需要抛异常,这时候就需要禁止SimpleDateFormat的自动计算功能. 这时 ...

  7. bzoj 2733: [HNOI2012]永无乡 离线+主席树

    2733: [HNOI2012]永无乡 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1167  Solved: 607[Submit][Status ...

  8. 初识EL表达式

    1.EL最初出现在JSTL,后来引入JSP 2.核心作用:减少JSp中Java代码数量,同时方便修改 3.算术.逻辑.关系符号都是两种,防止出现歧义,比如:/和div,%和mod,>=和ge,相 ...

  9. JSP环境配置

    为免以后忘记,记下了. Jdk在C盘,tomcat在D盘. 1.JAVA_HOME C:\Program Files\Java\jdk1.7.0_07 2.CATALINA_HOME D:\apach ...

  10. JBoss for luna

    Redhat官方手顺 貌似已经404了,搬运地址 我的Eclipse是Luna,每次进入Eclipse Market去装 http://marketplace.eclipse.org/content/ ...