kuangbin專題一 簡單搜尋 M 非常可樂

2021-08-19 07:23:34 字數 954 閱讀 2458

大家一定覺的運動以後喝可樂是一件很愜意的事情,但是seeyou卻不這麼認為。因為每次當seeyou買了可樂以後,阿牛就要求和seeyou一起分享這一瓶可樂,而且一定要喝的和seeyou一樣多。但seeyou的手中只有兩個杯子,它們的容量分別是n 毫公升和m 毫公升 可樂的體積為s (s<101)毫公升 (正好裝滿一瓶) ,它們三個之間可以相互倒可樂 (都是沒有刻度的,且 s==n+m,101>s>0,n>0,m>0) 。聰明的acmer你們說他們能平分嗎?如果能請輸出倒可樂的最少的次數,如果不能輸出"no"。

input三個整數 : s 可樂的體積 , n 和 m是兩個杯子的容量,以"0 0 0"結束。output如果能平分的話請輸出最少要倒的次數,否則輸出"no"。sample input

7 4 3

4 1 3

0 0 0

sample output
no

3

這道題是bfs沒有記錄路徑,開始的位置判斷是奇數還是偶數,這應該叫剪枝吧。。。。,但是dx,dy不是像以前一樣,這次的dx,dy要判斷是否倒滿。。。

#include#include#includeusing namespace std ;

typedef long long ll;

typedef unsigned long long ull;

const int _max =150;

int v[3],half;

bool vis[_max][_max][_max];

struct node;

void bfs( )

else

if(vis[next.w[0]][next.w[1]][next.w[2]])

q.push(next);}}

} } }

cout << "no" << endl ;

}int main()

return 0;

}

kuangbin專題一 簡單搜尋

poj 1426 找出乙個由1和0組成的十進位制數m滿足m為n的倍數。有兩種做法,一種是bfs從低位數往高位數搜,另一種是用二叉樹陣列的結構存每次的求出來的餘數,當餘數為0時返回下標,然後根據下標求出其對應的數。1.bfs include includeusing namespace std con...

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 ...