(简单) POJ 1426 Find The Multiple,BFS+同余。
Description
#include<iostream>
#include<cstring> using namespace std; long long ans[]; bool panduan(int a,int b)
{
long long num=;
long long base=; while(b)
{
if(b%)
num+=base;
base*=;
b/=;
} if(num%a==)
{
ans[a]=num;
return ;
} return ;
} int main()
{
int cou=;
for(int i=;i<=;i+=)
if(i%)
{
for(int j=;j<(<<);++j)
if(panduan(i,j))
{
break;
}
} int k,rem; ios::sync_with_stdio(false); for(cin>>k;k;cin>>k)
{
rem=;
while(k%==)
{
k/=;
++rem;
}
while(k%==)
{
k/=;
++rem;
}
cout<<ans[k];
for(int i=;i<rem;++i)
cout<<;
cout<<endl;
} return ;
}
这是第二遍的:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<utility> using namespace std; int que[],las,fir; void showans(int x)
{
int ans[];
int cou=; while(x)
{
if(x&)
ans[cou++]=;
else
ans[cou++]=; x=x>>;
} for(int i=cou-;i>=;--i)
cout<<ans[i]; cout<<endl;
} inline void getans(int n)
{
las=fir=; int cou=;
int temp; que[las++]=; while(las-fir)
{
++cou;
temp=que[fir++]; if(!temp)
{
showans(cou);
return;
} que[las++]=(temp*)%n;
que[las++]=(temp*+)%n;
}
} int main()
{
ios::sync_with_stdio(false); int n; for(cin>>n;n;cin>>n)
{
getans(n);
} return ;
}
(简单) POJ 1426 Find The Multiple,BFS+同余。的更多相关文章
- 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 搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18012 Accepted: 729 ...
- POJ 1426 Find The Multiple BFS
没什么好说的 从1开始进行广搜,因为只能包涵0和1,所以下一次需要搜索的值为next=now*10 和 next=now*10+1,每次判断一下就可以了,但是我一直不太明白我的代码为什么C++提交会错 ...
- poj 1426 Find The Multiple ( BFS+同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18390 Accepted: 744 ...
- 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 (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
随机推荐
- bjective-C 中核心处理字符串的类是 NSString 与 NSMutableString
Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重 ...
- GDT、GDTR、LDT、LDTR的理解
GDT是全局描述附表,主要存放操作系统和各任务公用的描述符,如公用的数据和代码段描述符.各任务的TSS描述符和LDT描述符.(TSS是任务状态段,存放各个任务私有运行状态信息描述符)LDT是局部描述符 ...
- Jquery树控件ZTree异步加载
异步加载的意思就是: 当点击展开树节点时,才去请求后台action返回点击节点的子节点数据并加载. 这里面主要设计ztree的setting变量的async属性设置: var setting = { ...
- Lucene 简单手记http://www.cnblogs.com/hoojo/archive/2012/09/05/2671678.html
什么是全文检索与全文检索系统? 全文检索是指计算机索引程序通过扫描文章中的每一个词,对每一个词建立一个索引,指明该词在文章中出现的次数和位置,当用户查询时,检索程序就根据事先建立的索引进行查找,并将查 ...
- cocos2d3.8.1 使用prebuild提升发布android速度
1.生成cocos prebuild库 cocos gen-libs -m debug或 cocos gen-libs -m release 2.使用命令创建test项目 cocos new test ...
- HDU 5480 Conturbatio
区间求和不更新,开个数组记录一下前缀和就可以了 #include<cstdio> #include<cstring> #include<cmath> #includ ...
- VS2013编译FileZilla0.9.44
2014年,FileZilla更新了一下,到了44版本了,貌似也是用VS2013的工程做的项目,所以下载了server的安装包,然后安装SourceCode即可(需要安装InterFace,是安装必选 ...
- 【项目笔记】布局文件报错Suspicious size: this will make the view invisible, probably intended for layout_width
写着写着就懵逼了,一直以为布局文件没写错啊,horizontal就是竖直啊,原来布局文件报错,不仅仅需要从报错的地方解决问题,还需要从其他地方去分析. 很明显是方向orientation选错了,应该写 ...
- 在数据库里面有这么一个表:用m代表男,用f代表女,现在我要输出格式为中文的:男和女,sql语句该怎么写
在数据库里面有这么一个表:用m代表男,用f代表女,现在我要输出格式为中文的:男和女, sql语句该怎么写 select case sex when 'm' then '男' else '女' a ...
- 简单的js实现网页时钟
js实现时钟. <div id="clock"></div> <script type="text/javascript"> ...