BFS 或 同余模定理(poj 1426)
题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数。
思路:nonzero multiple 非零倍数 啊。
英语弱到爆炸,理解不了题意。。。。。
STL 在c++过不了, 一直TLE,
最后只好看了下大神的代码。
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 50005
const double PI = acos(-1.0);
typedef long long LL ;
LL n;
LL cal(LL n){
queue <LL> s;
LL pos = , x;
s.push(pos);
while(){
pos = s.front();
for(LL i = ; i<; i++){
x = pos * + i;
if(x%n == ) return x;
s.push(x);
}
s.pop();
}
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%I64d", &n) && n){
if(n == ) {
printf("%I64d\n", n);
continue;
}
printf("%I64d\n", cal(n));
}
return ;
}
还有种使用模运算的:
(a*b)%n = (a%n *b%n)%n
(a+b)%n = (a%n +b%n)%n
http://blog.csdn.net/lyy289065406/article/details/6647917
BFS 或 同余模定理(poj 1426)的更多相关文章
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ 1426 Find The Multiple && 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21436 Accepted: 877 ...
- poj 1426 Find The Multiple ( BFS+同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18390 Accepted: 744 ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ - 1426 暴力枚举+同余模定理 [kuangbin带你飞]专题一
完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说 ...
- poj 1426 Find The Multiple( bfs )
题目:http://poj.org/problem?id=1426 题意:输入一个数,输出这个数的整数 倍,且只有0和1组成 程序里写错了一个数,结果一直MLE.…… #include <ios ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer
题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
随机推荐
- 便捷的php操作mysql库MysqliDb
github 地址:https://github.com/joshcam/PHP-MySQLi-Database-Class MysqliDb -- Simple MySQLi wrapper and ...
- springmvc跳转和重定向
如果springmvc返回的视图中带有redirect:或者forward:,springmvc会进行特殊处理, redirect:会执行重定向,forward:会执行转发操作! @RequestMa ...
- for语句
一.for语句的格式格式1:for (控制变量初始化表达式;条件表达式;增量表达式) 语句1; 格式2:for (控制变量初始化表达式;条件表达式;增量表达式){ 语句1; 语句2; -} 注意 ...
- hihocoder 1391 [扫描线]
/* 题意: 两方对阵,互发导弹.防护罩可以让导弹原速反向. 每一枚导弹有发射时间航行时间伤害值. 防护罩也有开启时间和防御时间. 其中一方防护罩开启时间已知,求另一方防护罩合理安排开启时间使得己方受 ...
- 【解决】SharePoint集成模式下Reporting Service—为用户授予的权限不足,无法执行此操作。 (rsAccessDenied)
环境:Windows Server 2008 R2 SP1,SharePoint 2010 企业版,SQL Server 2008 R2 Reporting Service(SharePoint集成模 ...
- ios系统的中arm指令集
arm结构处理器,几乎所有的手机都基于arm,其在嵌入式系统中应用非常广泛. ARM 处理器因为低功耗和小尺寸而闻名,它的性能在同等功耗的产品中也很出色.这里我们注意一点,模拟器并不运行arm代码,软 ...
- input自动获取焦点
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>te ...
- 自动化脚本过程中出现This element neither has attached source nor attached Javadoc...的解决方法
This element neither has attached source nor attached Javadoc and hence no Javadoc could be found Ec ...
- 纸上谈兵:排序算法简介及C实现
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 排序算法(Sorting Algorithm)是计算机算法的一个组成部分. 排序的 ...
- Dig out deleted chat messages of App Skype
Last month Candy was arrested on suspicion of having doing online porn webcam shows, but Candy refus ...