POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
http://poj.org/problem?id=1426
Description
Input
Output
Sample Input
2
6
19
0
Sample Output
10
100100100100100100
111111111111111111
大致题意:
给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成。
没看见是Special Judge
题解:
我感觉这题能够是投机取巧,输出结果根本就没有100位,之前以为是大数,一直没敢做,谁知是一个超级大坑题。
还有给的测试数据给的那么大,害我一看测试数据就不敢做了。还有为什么我用STL中的queue用C++交超时,而用G++就A了
,而自己写的结构体用C++交就过了。
主要思想:
和二叉树差不多,1->10,11;10->100,101,11->110,111.....
就是q.push(t*10);q.push(t*10+1);
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n;
struct node
{
long long int x;
} q[];
struct node t,f;
void bfs()
{
int s=;
int e=;
t.x=;
q[e++]=t;
while(s<e)
{
t=q[s++];
if(t.x%n==)
{
printf("%lld\n",t.x);
break;
}
f.x=t.x*;
q[e++]=f;
f.x=t.x*+;
q[e++]=f;
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n!=)
{
bfs();
}
return ;
}
G++;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
using namespace std;
int n;
long long t;
void bfs()
{
queue<long long >q;
q.push();
while(!q.empty())
{
t=q.front();
q.pop();
if(t%n==)
{
printf("%lld\n",t);
break;
}
q.push(t*);
q.push(t*+);
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n!=)
{
bfs();
}
return ;
}
POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)的更多相关文章
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
- Yet Another Multiple Problem(bfs好题)
Yet Another Multiple Problem Time Limit : 40000/20000ms (Java/Other) Memory Limit : 65536/65536K ( ...
- nyoj--523--亡命逃窜(BFS水题)
亡命逃窜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 从前有个叫hck的骑士,为了救我们美丽的公主,潜入魔王的老巢,够英雄吧.不过英雄不是这么好当的.这个可怜的娃被魔 ...
- POJ3287(BFS水题)
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- POJ 3126 Prime Path bfs, 水题 难度:0
题目 http://poj.org/problem?id=3126 题意 多组数据,每组数据有一个起点四位数s, 要变为终点四位数e, 此处s和e都是大于1000的质数,现在要找一个最短的路径把s变为 ...
- codeforces 811 D. Vladik and Favorite Game(bfs水题)
题目链接:http://codeforces.com/contest/811/problem/D 题意:现在给你一个n*m大小的图,你输出一个方向之后,系统反馈给你一个坐标,表示走完这步之后到的位子, ...
- (简单) POJ 1426 Find The Multiple,BFS+同余。
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
随机推荐
- FastCGI在nginx中的参数
FastCGI参数 fastcgi主要用于http调用外部解释器的接口,采用c/s结构,可以将http服务器和脚本解析器分开,同时在脚本解析服务器上启动一个或者多个脚本解析守护进程.当HTTP服务器每 ...
- python中级---->pymongo存储json数据
这里面我们介绍一下python中操作mangodb的第三方库pymongo的使用,以及简单的使用requests库作爬虫.人情冷暖正如花开花谢,不如将这种现象,想成一种必然的季节. pymongo的安 ...
- Esper学习之一:Esper介绍
CEP即Complex Event Process,中文意思就是“复杂事件处理”.听起来好像很复杂,实际上就是基于事件流进行数据处理,把要分析的数据抽象成事件,然后将数据发送到CEP引擎,引擎就会根据 ...
- Dropbox 在 Ubuntu 上需要认证授权的问题
在 Ubuntu 上,通过 Ubuntu软件中心 搜索下载安装了 Dropbox . 运行时,弹出如下图的提示. 输入密码,点击 授权 后,没有出现 Dropbox 的运行界面. 再次点击运行,仍会出 ...
- Nginx学习之keepalive
当然,在nginx中,对于http1.0与http1.1也是支持长连接的.什么是长连接呢?我们知道,http请求是基于TCP协议之上的,那么,当客户端在发起请求前,需要先与服务端建立TCP连接,而每一 ...
- SQL Server2008 R2 安装失败后的解决办法
当你第一次安装SQL Server2005,SQL Server2008,SQL Server2012失败后,第二次重新安装一般还是容易安装失败,原因就是你没有完全卸载,还存留残留文件和注册表. 我安 ...
- nodeJS删除文件
var fs = require("fs"); var path = require("path"); deleteFolderRecursive = func ...
- thinkCMF----调用幻灯片
还是在Common.php上写: /* * slide 获取幻灯片 * 具体使用: <?php $slide = slide();?> <foreach name="sli ...
- Elasticsearch 不同的搜索类型之间的区别
1.match 轻量级搜索 GET /wymlib/_search { "query": { "match": { "title": ...
- matplotlib的下载和安装方法
官网:http://matplotlib.org/ Installation节 Visit the Matplotlib installation instructions. Installing节 ...