POJ-1426.Findthemultiple.(BFS)
一开始模拟了一波大数取余结果超时了,最后改成long long过了emmm...
本题大意:给出一个200以内的数n,让你找出一个m使得m % n == 0,要求m只有1和0组成。
本题思路:BFS模拟即可。
参考代码:
#include <cstdio>
#include <queue>
using namespace std; int mod;
typedef long long LL; LL bfs() {
LL now = ;
queue <LL> s;
s.push(now);
while(!s.empty()) {
LL cur = s.front();
s.pop();
for(int i = ; i < ; i ++) {
LL next;
if(i == ) {
next = cur * + ;
} else next = cur * ;
if(next % mod == ) return next;
s.push(next);
}
}
return ;
} int main () {
while(~scanf("%d", &mod) && mod) {
LL ans = bfs();
printf("%lld\n", ans);
}
return ;
}
顺便给出模拟大数取余的代码。
#include <string>
#include <iostream>
using namespace std; int main () {
int mod;
string s;
while(cin >> mod >> s) {
int ans = ;
for(int i = ; i < s.length(); i ++)
ans = (ans * + s[i] - '') % mod;
cout << ans << endl;
}
return ;
}
POJ-1426.Findthemultiple.(BFS)的更多相关文章
- Find The Multiple POJ - 1426 (BFS)
题目大意 给定一个整数,寻找一个只有0,1构成的十进制数使得这个数能够整除这个整数 解法 直接bfs第一位放入1,之后每一位放入1或者0 代码 #include <iostream> #i ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- poj 1426 Find The Multiple( bfs )
题目:http://poj.org/problem?id=1426 题意:输入一个数,输出这个数的整数 倍,且只有0和1组成 程序里写错了一个数,结果一直MLE.…… #include <ios ...
- POJ 1426 - Find The Multiple - [DP][BFS]
题目链接:http://poj.org/problem?id=1426 Given a positive integer n, write a program to find out a nonzer ...
- poj 1426 Find The Multiple (bfs 搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18012 Accepted: 729 ...
- Poj(1426),BFS
题目链接:http://poj.org/problem?id=1426 可能数据比较水,没有用到大整数.刚刚开始的时候,想从后往前加0或者1,发现有点难写,后来想到先放一个1,再1*10,1*10+1 ...
随机推荐
- Gson 解决时间解析问题
异常: at org.eclipse.jdt.) at org.eclipse.jdt.) Caused by: java.text.ParseException: Failed to parse d ...
- VC中链接错误,提示string重定义
VC链接错误,说是string已经有了实现了,只要 rebuild 一下好了. Linking...LINK : warning LNK4075: ignoring '/EDITANDCONTINUE ...
- delphi RTTI 四 获取类属性列表
delphi RTTI 四 获取类属性列表 GetPropList(btn1.ClassInfo, tkAny, PropList) PropCount := GetTypeData(btn1.Cla ...
- Spring cloud info信息显示
父工程添加配置如下 <build> <finalName>microservicecloud</finalName> <resources> <r ...
- flash时间轴声音大小控制
A2时间轴声音大小控制: var sound:Sound = new Sound(); sound.setVolume(200); 把背景音乐放到一个影片剪辑里,剪辑起名 例如bgm_mc 声音模式为 ...
- dpkg卸载
from:https://jingyan.baidu.com/article/f54ae2fc2724a71e92b849c4.html 选择 dpkg -l来查看软件的状态. 选择 dpkg -P来 ...
- oc字符串与c字符串转换和拷贝
// Helper method to create C string copy NSString* MakeNSString (const char* string) { if (string) { ...
- maven中scope标签详解
前言 最近在做itoo的pom优化工作,发现对于maven依赖管理中的scope标签还是有不明白的地方,所以今天就来总结一下这方面的知识,scope在maven的依赖管理中主要负责项目的部署 mave ...
- replace()方法解析
search(),match(),用于查找指定字符串返回首次出现的索引值与指定的字符串.这篇我们讲找到指定字符串之后将其替换掉.直接贴: var str="Visit Microsoft!& ...
- SimpleDateFormat 使用时出现的线程同步问题。。。
错误使用: public static final SimpleDateFormat DAY_UI_MONTH_DAY_FORMAT = new SimpleDateFormat("MM-d ...