Find The Multiple POJ - 1426
技術標籤:簡單搜尋
Find The Multiple POJ - 1426
思路:直接bfs搜帶1和0的所有數,直到能被n整除
有點玄學,C++超時,G++卻能AC
程式碼如下
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
ll n;
void bfs(){
queue<ll> q;
q.push(1);
while(q.size()){
ll t = q.front();
q.pop();
if (t % n == 0){
cout << t << endl;
return;
}
ll x = t*10; //搜尋t*10
ll y = x+1; //搜尋t*10+1
q.push(x); q.push(y);
}
}
int main(){
while(cin>>n, n){
bfs();
}
return 0;
}
相關推薦
Find The Multiple POJ - 1426
技術標籤:簡單搜尋 Find The Multiple POJ - 1426 題目 思路:直接bfs搜帶1和0的所有數,直到能被n整除 有點玄學,C++超時,G++卻能AC
POJ 1426 Find The Multiple
題目如下: 在2100年科學家發現了平行宇宙,但是新發現的Earth2的世界中所有數字都是由0和1組成的十進位制數,如果從我們的世界穿越到Earth2,數字將發生一些變化,例如:一個正整數n,將被轉化為n的一個非零的倍數m
題解 UVA1189 【Find The Multiple】
實際發表時間:2020-03-28 \\(Python\\)打表!!! 這題看上去跟\\(P2841\\)差不多 可以用那題的程式打表
D - Find The Multiple
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 ther
D - Find The Multiple(2)
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
Could not find the Qt platform plugin windows錯誤解決方法
在PyCharm中執行PyQt5視窗程式時,出現了下圖所有的錯誤提示。 出現該問題的原因是環境變數沒有新增。
1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K
問題: 求Fibonacci數列中,最少多少個數之和為K 數列中元素可重複使用。 Example 1:
287. Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi
nginx: [emerg] CreateDirectory() "D:\tools\nginx-1.14.0/temp/client_body_temp" failed (3: The system cannot find the path specified)
在Windows中啟動nginx提示如下資訊 nginx: [emerg] CreateDirectory() \"D:\\tools\\nginx-1.14.0/temp/client_body_temp\" failed (3: The system cannot find the path specified)
1535. Find the Winner of an Array Game
Given an integer arrayarrofdistinctintegers and an integerk. A game will be played between the first two elements of the array (i.e.arr[0]andarr[1]). In each round of the game, we comparearr[0]witharr
[k8s]Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
檢視容器資源報錯 kubectl top nodes kubectl top pods [root@master ~]# kubectl top nodes Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
GenomicRangeQuery Find the minimal nucleotide from a range of sequence DNA.
Task description A DNA sequence can be represented as a string consisting of the lettersA,C,GandT, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has
Finding max and min in arrays Find the index of K min in an array
Implement a method that finds the index of the K-th element equal to the minimum in an array of ints. If no such element can be found, return -1. The input array can be empty, K > 0.
Finding max and min in arrays Find the second largest element in an array
Implement a method to find the second largest number in an array of ints. If the input array is empty or contains only a single number, the method must return Integer.MIN_VALUE.
SP1772 Find The Determinant II
題意 \\(T\\) 組資料,每組給定兩個整數 \\(n,k\\),求 \\(\\det A\\),其中 \\(A\\) 為一個 \\(n\\times n\\) 的矩陣且 \\(A_{i,j}=\\gcd(i,j)^k\\),對 \\(10^6+3\\) 取模。
1283. Find the Smallest Divisor Given a Threshold (M)
Find the Smallest Divisor Given a Threshold (M) 題目 Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the resu
【LeetCode】287. Find the Duplicate Number 尋找重複數(Medium)(JAVA)
技術標籤:Leetcodeleetcodejava演算法面試資料結構 【LeetCode】287. Find the Duplicate Number 尋找重複數(Medium)(JAVA)
Codeforces Round #689 (Div. 2, based on Zed Code Competition)-B. Find the Spruce(DFS+記憶化搜尋)
技術標籤:acm競賽c++ 題目連結 Codeforces Round #689 (Div. 2, based on Zed Code Competition)-B. Find the Spruce
Codeforces Round #689 (Div. 2, based on Zed Code Competition)/1461B Find the Spruce
題目連結:https://codeforces.com/contest/1461/problem/B 題目大意:給定一個矩陣,求其中樓梯狀等腰三角形(叫它等腰樓梯吧0v0)的個數
【CF1463B】Find The Array
技術標籤:數學 Find The Array 簡介程式碼 簡介 昨天Educational Round的一題,就是新的數列和原數列的絕對值之差的和小於原數列和的一半,可以考慮構造一個以1為首項2為公比的等比數列,每次都確定小於等於