poj1426 Find The Multiple
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 14622 | Accepted: 5938 | Special Judge | ||
Description
Input
Output
Sample Input
2
6
19
0
Sample Output
10100100100100100100111111111111111111
就是找倍数,bfs 这题 就是宽搜,我打/*号的是深搜的代码 ,但是很慢,也过不了,很容易就RUNTIME去了!
#include<iostream>
#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
stack<int > q;
struct hal{
int x,leave,floor,front; }l[300000];
int visit[300];
int n,re;
bool init(int num,int flag)
{
/*
l[num].x=flag;
if(flag==0)
{ l[num].leave=(l[num>>1].leave*10)%n;
if(visit[l[num].leave])
return false;
visit[l[num].leave]=1;
l[num].floor=l[num>>1].floor+1;
if(l[num].leave==0)
{
re=num;
return true;
}
if(l[num].floor>200)
return false; }
else if(flag==1)
{
l[num].leave=(l[num>>1].leave*10+1)%n;
if(visit[l[num].leave])
return false;
visit[l[num].leave]=1;
l[num].floor=l[num>>1].floor+1;
if(l[num].leave==0)
{
re=num;
return true;
}
if(l[num].floor>200)
return false; }
else if(flag==-1)
{ l[num].leave=1;
l[num].x=-1;
l[num].floor=1;
} if(init(num<<1,0))
return true;
if(init(num<<1|1,1))
return true;
return false;
*/
int t,w,j;
t=w=1;
l[t].x=-1;
l[t].leave=1;
l[t].floor=1;
l[t].front=-1;
while(t<=w)
{
for(j=0;j<=1;j++)
{
l[++w].floor=l[t].floor+1;
l[w].front=t;
l[w].x=j;
if(j==0)
l[w].leave=(l[t].leave*10)%n;
else
l[w].leave=(l[t].leave*10+1)%n; if(visit[l[w].leave])
{
w--;
continue; }
visit[l[w].leave]=1; if(l[w].leave==0)
{
re=w;
return true;
}
if(l[w].floor>200)
{ continue; }
}
t++;
}
return false;
}
bool bfs(int e)
{
while(l[e].x!=-1)
{
q.push(l[e].x);
e=l[e].front;
}
printf("1");
while(!q.empty())
{
printf("%d",q.top());
q.pop();
}
printf("\n");
return true;
}
int main ()
{ while(scanf("%d",&n)!=EOF&&n)
{
memset(visit,0,sizeof(visit));
visit[1]=1;
l[1].leave=-1;
init(1,-1);
//printf("%d",re);
bfs(re);
}
return 0;
}
poj1426 Find The Multiple的更多相关文章
- POJ1426——Find The Multiple
POJ1426--Find The Multiple Description Given a positive integer n, write a program to find out a non ...
- POJ1426 Find The Multiple (宽搜思想)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24768 Accepted: 102 ...
- poj1426 Find The Multiple(c语言巧解)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36335 Accepted: 151 ...
- POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...
- POJ1426 Find The Multiple —— BFS
题目链接:http://poj.org/problem?id=1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Tota ...
- poj1426 Find The Multiple (DFS)
题目: Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41845 Accepted: ...
- POJ1426 Find The Multiple 解题报告
参考:http://www.cnblogs.com/ACShiryu/archive/2011/07/24/2115356.html #include <iostream> #includ ...
- poj1426 - Find The Multiple [bfs 记录路径]
传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) #include<iostream> ...
- POJ1426——Find The Multiple (简单搜索+取余)
题意: 给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除. 用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择,换而言之是一个双入口BFS. ...
随机推荐
- UITableView 滚动时隐藏键盘
#pragma mark - UItableView滚动时收键盘 - (void)scrollViewWillBeginDragging:(UITableView *)scrollView { [se ...
- web前端 - 模态对话框
代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...
- 解决WCF 调用方未由服务器进行身份验证或消息包含无效或过期的安全上下文令牌
错误描述: 1. WCF:调用方未由服务器进行身份验证 2. 无法处理消息.这很可能是因为操作“http://tempuri.org/ISCCLSvc/GetCarriersByWareHouse”不 ...
- 概率dp ZOJ 3640
Help Me Escape Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- ajax局部刷新分页
//请求数据加载绑定页面 function DindAjax(pageIndex) {//获取参数 var colors = $("#colorsVal").val(); $.aj ...
- ScriptManager局部刷新
ScriptManager和UpdatePanel控件联合使用可以实现页面异步局部更新的效果.其中的UpdatePanel就是设置页面中异步局部更新区域,它必须依赖于ScriptManager存在,因 ...
- .net 地址栏传中文乱码 的解决方法
1.设置web.config文件. <system.web> ...... <globalization requestEncoding="gb2312" res ...
- Android 使用开源xUtils来实现多线程下载(非原创)
1.程序员自己也是可以实现多线程下载的,只是代码量比较大,而且,其中有许多细节需要考虑到,在GitHub上有人写好的代码,我们可以拿过来使用下,节省了我们开发程序的时间 2.导包:xUtils-2.6 ...
- String.format Tutorial
String format(String format, Object... args) The format specifiers for general, character, and numer ...
- Excel Aspose.Cells 设置单元格格式 为数字
Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[]; //工作表 sheet.Cells ...