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 ...
随机推荐
- java json字符串与对象转换
下载引入包gson-2.0.jar 1.字符转数据 final Map map = new HashMap();map.put("contents", "[{\&q ...
- js处理数据库时间格式/Date(1332919782070)/
js处理数据库时间格式 数据库返回时间格式:/Date(1332919782070)/ 方法: function ChangeDateFormat(val) { if (val != null) { ...
- java多态和继承
继承定义:子类继承父类的特征和行为,使得子类具有父类的各种属性和方法.或子类从父类继承方法,使得子类具有父类相同的行为. 多态定义看了很多,都觉得不够贴切,后来在一个同学的笔记中看到了如下的定义觉得很 ...
- day04-完整性约束
完整性约束 关键字: not null 与 default unique primary auto_increment foreign key 1.介绍 约束条件与数据类型的宽度一样,都是可选参数作用 ...
- SpringBoot配置定时任务的两种方式
一.导入相关的jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- js 编写一个神奇的四则运算
写一个算法,有时候可以用简单的方法就可以写出来,但是只能针对特定的环境,如果要能够适应不同的环境,就需要对算法进行优化,在优化的过程中,你会觉得非常神奇,下面来看一个简单的四则运算的算法编写方式: 1 ...
- jquery接触初级-----ajax 之:jquery_ajax 方法
1. $.get() 方法: 格式:$.get( url,[,data],[,callback],[,type] ); data: 采用键值对的方式存储于对象中; callback: 载入成功时(当 ...
- Java读写avro例子
一.avro是一个数据序列化框架,可以高效得进行序列化和反序列化,支持C, C++, C#, Java, PHP, Python, 和Ruby语言.现在使用Java来读写. 二.环境搭建 1.下载av ...
- Nginx使用GZIP来压缩网页
HTTP协议上的GZIP编码是一种用来改进web应 用程序性能的技术.大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度.这一般是指WWW服务器中安装的一个功能,当有人来访问这个服务器中 ...
- 点击对应不同name的button,显示不同name的弹窗(弹窗功能)
(通过html5方法自定义属性选择,因此会有兼容性,此方法可适用移动端) 将button的name,与弹窗的name设为变量,作为参数传递. Button的name可以是自定义name,HTML5自定 ...