POJ-1426-Find the multiply】的更多相关文章

POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Accepted: 10613   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representati…
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至找到满足条件的数,注意最高位一定为1 假设 n=6  k即为当前所求的目标数,不满足条件则进一步递推 (i 为层数(深度),在解法二的优化中体现,此时可以不管) 1%6=1 (k=1) i=1 { (1*10+0)%6=4 (k=10) i=2 { (10*10+0)%6=4 (k=100) i=4…
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may as…
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个数字只能是1 * 10或者1 * 10 + 1.就按照这种方式枚举,依次放入队列,如果是其的倍数,就输出. 一开始没理解题意,以为是找一个能整除的二进制数,错了半天. 代码总览 #include <cstdio> #include <cstring> #include <algo…
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************************ Author :Running_Time Created Time :2015-8-2 14:21:51 File Name :POJ_1426.cpp *************************************************/ #include…
http://poj.org/problem?id=1426 一道广搜的题目. 题意就是给你一个n,要你求出n的倍数中,只存在0和1的那个数字 所谓的只存在0和1,那么就是某个数的十倍或者十倍+1,而那个最开始的数应该是1. Memory :5504K G++ runtime:391MS #include <iostream> #include <queue> using namespace std; int n; queue <long long >s; void b…
题目:http://poj.org/problem?id=1426 题意:输入一个数,输出这个数的整数 倍,且只有0和1组成 程序里写错了一个数,结果一直MLE.…… #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<iomanip> #inclu…
题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there…
题目链接:http://poj.org/problem?id=1426 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a correspo…
转载自:優YoU  http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem?id=1426 题意 给出一个整数n,(1 <= n <= 200).求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成. 分析 首先暴力枚举肯定是不可能的 1000ms 想不超时都难,而且枚举还要解决大数问题.. 要不是人家把这题放到搜索,怎么也想不到用BFS... 解题方法: B…
http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+1转移,只存储余数即可, 对于余数i,肯定只有第一个余数为i的最有用,只记录这个值即可 #include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=222…
题目链接:http://poj.org/problem?id=1426 可能数据比较水,没有用到大整数.刚刚开始的时候,想从后往前加0或者1,发现有点难写,后来想到先放一个1,再1*10,1*10+1,这样也可以存遍历这种只有0和1的数,但是发现STL写队列会T,后来队列自己写,就A了. #include <stdio.h> ]; int main() { int n; while(scanf("%d",&n),n) { ; ; Q[rear++] = ; ) {…
题目链接 http://poj.org/problem?id=1426 题意 给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n n 不超过 200 十进制数字位数 不超过100 思路 其实 十进制数字位数 不超过 20 下就有可以满足的答案 所以直接用 unsinged long long 就可以过了 .. AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #include…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18012   Accepted: 7297   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* DFS */ #include <cstdio> #include <iostream> #include <algorithm> #include <queue> using namespace std; long long n; int DEEP; bool…
注:本人英语很渣,题目大意大多来自百度~=0=   这个题有点坑,答案不唯一   题目大意:给你一个数n, 你需要输出的是一个由1和0组成的数,此数能被n整除   解题思路:用s = 1做数的起点, s*10则相当于在后面加上0, s*10+1代表在后面加1, 用long long 来保存s足够了, 每次判断一下s % n  符合条件则输出 当然用dfs不能无限寻找下去  比如你第一次10000...0 假如n是奇数不可能有结果 所以每次递归记录一下层数: long long 的范围是-9223…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 11828   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
题目:Find The Multiple 题意:求给出的数的倍数,该倍数是只由 1与 0构成的10进制数. 思路:nonzero multiple  非零倍数  啊. 英语弱到爆炸,理解不了题意..... STL 在c++过不了,  一直TLE, 最后只好看了下大神的代码. #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <c…
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo…
没什么好说的 从1开始进行广搜,因为只能包涵0和1,所以下一次需要搜索的值为next=now*10 和 next=now*10+1,每次判断一下就可以了,但是我一直不太明白我的代码为什么C++提交会错,G++则正确. #include<cstdio> #include<stdio.h> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #i…
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo…
完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说一下同余模定理:如果(a - b) / m = 0,说明a%m等于b%m,那么对于本题应该如何运用呢?  已知a % n = m,那么(a * 10 + x) % n = a * 10 % n + x % n = (a % n * 10 + x ) % n = (m *10 + x ) % n,有了…
题目: Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than…
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26926   Accepted: 11174   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21436   Accepted: 8775   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
E - Find The Multiple Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only…
Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18390   Accepted: 7445   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains…
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no mo…
题目大意 给定一个整数,寻找一个只有0,1构成的十进制数使得这个数能够整除这个整数 解法 直接bfs第一位放入1,之后每一位放入1或者0 代码 #include <iostream> #include <queue> using namespace std; int n; void bfs() { queue<long long> q; q.push(1); while(q.size()) { long long p=q.front(); q.pop(); if(p%n…