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 ...
随机推荐
- linux centos7.5修改主机名和ip永久生效
以centos7.5为例 1.修改主机名 [root@localhost ~]# hostname localhost.localdomain[root@localhost ~]# hostname ...
- Ubuntu下无法使用Secure_CRT连接服务器
虚拟机使用 1 .指令安装了SSH服务器 sudo apt-get install openssh-server 2. 输入命令 ps | grep ssh 查看SSH服务是否开启 显示服务已开启 3 ...
- Activity工作流学习(二)--Activity数据库
23张表 ACT_RE_资源库流程规划表 act_re_deployment 部署信息表 act_re_model 流程设计模型部署表 act_re_procdef 流程定义数据表 ACT_RU_运行 ...
- nginx 配置文件配置
server { listen 80 ; server_name test.com www.test.com; index index.html index.php index.htm; root / ...
- 函数参数,const 引用 和 非 const引用是不同的函数。
举个例子, void f(const int &x) 和 void f(int &x) 是不同的函数. 函数的返回值不能作为区分
- 尚硅谷springboot学习16-slf4j的使用
如何在系统中使用SLF4j 以后开发的时候,日志记录方法的调用,不应该来直接调用日志的实现类,而是调用日志抽象层里面的方法: 给系统里面导入slf4j的jar和 logback的实现jar impor ...
- 3:while、for 循环语句
循环就是重复的做一件事情.python 中的循环语句有 while 和 for. while 循环 while 循环必须得有一个计数器,否则会变成一个死循环. # 例如这段代码,这段程序运行之后会一直 ...
- javap——查看class文件的方法
有时候为了研究Javac的原理,要去看看class文件的内容是如何组织的,这时候很有必要查看class文件.方法有很多种,这里推荐使用JDK自带的javap工具. 首先建立如下源码: public c ...
- fengsuo
IP地址特定端口封锁 原理: 配合上文中特定IP地址封锁里路由扩散技术封锁的方法进一步精确到端口,从而使发往特定IP地址上特定端口的数据包全部被丢弃而达到封锁目的,使该IP地址上服务器的部分功能无法在 ...
- Asp.Net WebApi 学习记录(一)
刚创建的 Asp.Net Web Api 项目,在进行简单的测试时发现返回的 JSON 数据很丑陋.与平时我们使用的 JSON.NET 序列化出来的字符串不一样.通过下面的设置就可以了: // 清除所 ...