Find The Multiple POJ - 1426 (BFS)
題目大意
給定一個整數,尋找一個只有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==0) { cout<<p<<"\n"; return; } q.push(p*10); q.push(p*10+1); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while(cin>>n&&n) bfs(); }
相關推薦
Find The Multiple POJ - 1426 (BFS)
題目大意 給定一個整數,尋找一個只有0,1構成的十進位制數使得這個數能夠整除這個整數 解法 直接bfs第一位放入1,之後每一位放入1或者0 程式碼 #include <iostream> #include <queue> using namespace std; int n;
搜尋E Find The Multiple POJ - 1426
#acm/搜尋 Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains
Find a multiple POJ - 2356 (抽屜原理)
包含 假設 cstring printf 題意 for can n個元素 表示 抽屜原理: 形式一:設把n+1個元素劃分至n個集合中(A1,A2,…,An),用a1,a2,…,an分別表示這n個集合對應包含的元素個數,則:至少存在某個集合Ai,其包含元素個數值ai大於
POJ 3414 (BFS)
class cout () amp esp cst LV pan span 這道題還是比較簡單的,就是寫起來有點麻煩,剛開始做的時候一直一位有什麽簡單方法,拖了好久。。。還是自己分析問題的能力不行啊 1 #include<iostream> 2 #i
POJ 3126(BFS)
code stream using \n == bfs push string ostream 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #in
Find The Multiple POJ
E - Find The Multiple Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation cont
POJ 1426 Find The Multiple(DFS,BFS)
ons pro sum 數字 there lin queue hat 一個數 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal
POJ 1426 Find The Multiple(bfs)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains onl
POJ 1426 Find The Multiple(數論——中國同余定理)
定義 十進制 pro desc decimal tput one return solution 題目鏈接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a pro
Find The Multiple(POJ-1426)
Problem Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only t
poj 1426 Find The Multiple(打表找範圍+搜尋)
1426-Find The Multiple 題目連結http://poj.org/problem?id=1426 Time Limit: 1000MS Memory Limit: 10000K
POJ 1426 Find The Multiple 深搜廣搜(信題目你就完了系列)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43209 Accepted: 18144 Special Judge
poj 1426 Find The Multiple (簡單搜尋dfs)
題目: 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.
Find The Multiple(poj 1426)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33035 Accepted: 13823 Special Judge Description Giv
POJ 1426 Find The Multiple(kuangbin帶你飛 專題一:簡單搜尋)
題意:給定一個n,找一個能被n整除並且每一位都是0或者1的數字... 簡單bfs,第一位肯定是1,然後求得餘數,後面添一個0或者1的時候將當前餘數*10+0或者1....找到倍數後將字串後面補個‘\0’puts輸出就好了... #include<cstring>
POJ 1426 Find The Multiple && 51nod 1109 01組成的N的倍數 (BFS + 同余模定理)
ase 正整數 ng- eof ger put emp lan respond Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissio
POJ 1426 Find The Multiple(大數取模)【DFS】||【BFS】
++ printf true pty ace bfs 還要 ems 兩種 <題目鏈接> 題目大意: 給一個小於200的正整數n,問只有0和1組成的位數小於100的最小能被n整除的數是多少。 解題分析: 用DFS或者BFS沿著位數進行搜索,每一次搜索到下一位都有兩
POJ 1426 - Find The Multiple - [DP][BFS]
more reat namespace find hat array href 原理 write 題目鏈接:http://poj.org/problem?id=1426 Given a positive integer n, write a program to find
POJ-1426 Find The Multiple【BFS】
題目傳送門 題意: 給出一個整數n,(1 <= n <= 200)。求出任意一個它的倍數m,要求m必須只由十進位制的’0’或’1’組成。m第一個數字必須是1,且n不大於200,m不超過100個十進位制數字。 題解:BFS,M從1開始遍歷所有可能的值。不知道為什麼lo
POJ-1462-Find The Multiple (dfs搜尋)
原題連結: 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 representat