POJ1426 Find The Multiple —— BFS
题目链接:http://poj.org/problem?id=1426
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 34218 | Accepted: 14337 | Special Judge | ||
Description
digits.
Input
Output
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
Source
题解:
题目说答案的位数不会超过100,所以以为是:高精度 + 模运算。这样也太丧心病狂了吧!
后来实在想不到其他方法,就看了题解。结果是一道普通的搜索题,答案用long long存就够了(题目不是说位数<=100),感觉被骗了。
再一次受到了启发:面对一些题目(人生也如此)时,如果想到的方法似乎不能解决问题,但除此之外又无其他办法,那就就要放开手脚试一试,不要畏手畏脚。如果想到的唯一方法都搁置不试,那就相当于交白卷了;试一试,或许能出现意想不到的结果。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = +; queue<LL>q;
LL bfs(int n)
{
while(!q.empty()) q.pop();
q.push(); while(!q.empty())
{
LL x = q.front();
q.pop();
if(x%n==)
return x;
q.push(1LL*x*);
q.push(1LL*x*+);
}
} int main()
{
int n;
while(scanf("%d",&n) && n)
{
cout<< bfs(n) <<endl;
}
}
POJ1426 Find The Multiple —— BFS的更多相关文章
- poj1426 - Find The Multiple [bfs 记录路径]
传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) #include<iostream> ...
- POJ1426——Find The Multiple
POJ1426--Find The Multiple Description Given a positive integer n, write a program to find out a non ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...
- POJ1426Find The Multiple[BFS]
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27433 Accepted: 114 ...
- POJ1426 Find The Multiple (宽搜思想)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24768 Accepted: 102 ...
- ZOJ 1136 Multiple (BFS)
Multiple Time Limit: 10 Seconds Memory Limit: 32768 KB a program that, given a natural number N ...
- poj1426 Find The Multiple
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14622 Accepted: 593 ...
- POJ 1465 Multiple (BFS,同余定理)
id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS Memory Limit: 32768K T ...
随机推荐
- Spoj-NPC2015A Eefun Guessing Words
Eefun Guessing Words Eefun is currently learning to read. His way of learning is unique, by trying ...
- 联合权值(codevs 3728)
Description 无向连通图 G 有 n 个点,n−1 条边.点从 1 到 n 依次编号,编号为 i 的点的权值为 Wi,每条边的长度均为 1.图上两点 (u,v) 的距离定义为 u 点到 v ...
- .net面试题汇总-第二篇
本篇主要关注下,.net面试题中经常用的算法问题 1.有一群猴子,它们每天要吃桃子,它们第一天吃的数量是总量的一半再多一个,第二天吃的是第一天剩下的一半再多一个,第三天吃的是第二天剩下的一半多一个,以 ...
- 洛谷 P1616 疯狂的采药
传送门 题目描述 Description LiYuxiang是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给他出了一个难题.医师把他 ...
- 标准C程序设计七---14
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- 开始学习Objective-C
加油! 顺便试试这MarsEdit好用不~
- T2639 约会计划 codevs
http://codevs.cn/problem/2639/ 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而 ...
- codevs 2964公共素数因数
2964 公共素数因数 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 白银 Silver 题解 题目描述 Description 小单同学刚学习了一个数分解成几个素 ...
- Windows 10安装IntelliJ IDEA时快捷键冲突设置
Windows的快捷键的非常多,而且个性化软件获得这些权限的也很多,所以没有最终的方法,只能不断的发现和尝试. 下面是收集的一些教程,或许能在这里找到灵感: 切记:不建议优先修改IDEA的快捷键,应该 ...
- Linux下&/jobs/fg/bg命令的使用(转)
一.& 这个用在一个命令的最后,可以把这个命令放到后台执行. 二.[Ctrl]+[Z] 可以将一个正在前台执行的命令放到后台,并且暂停. 三.jobs 查看当前有多少在后台运行的命令. 四.f ...