kuangbin專題一 簡單搜尋

2021-09-17 01:54:13 字數 987 閱讀 8503

poj 1426

找出乙個由1和0組成的十進位制數m滿足m為n的倍數。

有兩種做法,一種是bfs從低位數往高位數搜,另一種是用二叉樹陣列的結構存每次的求出來的餘數,當餘數為0時返回下標,然後根據下標求出其對應的數。

1.bfs

#include#includeusing namespace std;

const int inf=0x3f3f3f3f,maxn=1000000000+7;

int cnt,row[15],m,n,ans=inf;

typedef long long ll;

queueque;

int main()

que.push(1);

ll x;

while (!que.empty())

else que.push(x*10);

if ((x*10+1)%n==0)

else que.push(x*10+1);

}printf("%lld\n",x);}}

2.二叉樹陣列

#include#include#includeusing namespace std;

const int inf=0x3f3f3f3f,maxn=1000000000+7;

int mod[1000000],cnt,row[15],m,n,ans=inf;

typedef long long ll;

int main()

i--;

vectorans;

while (i)

for (int u=ans.size()-1;u>=0;u--) printf("%d",ans[u]);

putchar('\n');}}

kuangbin專題一簡單搜尋總結

e find the multiple 題意 找乙個能整除n的數m,對m的要求是只有0和1組成。n不超過200,m長度不超過100.思路 很多人都寫了乙個假演算法,就是在unsigned long long 的範圍裡面找就行了,雖然也a了,但博主想在這裡提一下正確的思路。首先用到了同餘定理 即以任意...

kuangbin專題一 簡單搜尋 (完整)

1.poj 1321 棋盤排列 類似八皇后 poj 1321 棋盤排列 類似八皇后的排列搜尋。include include include using namespace std typedef long long ll int dp 11 11 char mp 11 11 int col 11 ...

KuangBin 專題一 簡單搜尋 Pots

include include include include include using namespace std cubagea是第乙個瓶子的容量 cubageb是第二個瓶子的容量 stdc是要達到的容量 int used 105 105 cubagea,cubageb,stdc 用於儲存兩個...