(简单) 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 ...
随机推荐
- python2.x 使用protobuf
1.在windows下配置protobuf 1.1 下载对应的包,包含两个:protoc.exe和源码文件(protoc也可以自己生成) 下载地址1 --- google code最近在迁移,也许以后 ...
- OpenGL ES着色器语言之变量和数据类型(二)(官方文档第四章)
OpenGL ES着色器语言之变量和数据类型(二)(官方文档第四章) 4.5精度和精度修饰符 4.5.1范围和精度 用于存储和展示浮点数.整数变量的范围和精度依赖于数值的源(varying,unifo ...
- Python作用域
以下依据Python 3 1.Python变量查找顺序为LEGB(L:Local,E:Enclosing,G:Global,B:Built-in). 2.实际上,在Python中,只有模块,类以及函数 ...
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
Android根据Button状态(normal,focused,pressed)显示不同背景图片 Android中Button 有focused, selected, pressed 等不同状态,通 ...
- ImageLoader的Jar包加载图片
注意:需要添加权限,若缓存图片第二个必须要加 <uses-permission android:name="android.permission.INTERNET" /> ...
- GameUnity 2.0 文档(三) 纸片人八方向
DirectSprite类 有别于 上篇文档出现的 AnimationSprite类 (从头播放到尾) 这个类根据 path的图,如果是 8*8 64个图 八方向,可以设置长宽和 角度 角度 代表 8 ...
- 线程带参数的Udp接收
//work wk = new work(ReadUdpDate); ParameterizedThreadStart parmThre = new ParameterizedThreadStart( ...
- AS3条件编译
package { import flash.display.Sprite; public class Main extends Sprite { public function Main() { s ...
- 前端知识复习二(js)
JS的作用 页面特效 移动端 异步交互(AJAX) 服务器端开发(node.js) 由ECMAScript和dom(操作网页上的api).bom组成(操作浏览器的部分api) 输出到页面内容 cons ...
- Windows API 之 CreateThread、GetExitCodeThread(未完)
GetExitCode Retrieves the termination status of the specified thread. BOOL WINAPI GetExitCodeThread( ...