poj 2912 列舉 種類並查集

2021-08-19 07:26:44 字數 1167 閱讀 5186

題意:多個人玩石頭剪刀布,每個人提前選定了自己出哪個手勢,而其中有一種特殊的人他可以隨意出什麼手勢,問是否能夠從給出的一系列石頭剪刀布遊戲中判斷出哪個是特殊的,可以從第幾局遊戲中判斷出來。

定義0, 1, 2為三種手勢,列舉每乙個人,對於這個人不進行並查集操作,看剩下的會不會有矛盾,沒有的話就可能是。局數就是列舉其他所有人出現矛盾的遊戲場次的最大值,因為只有否定完其他所有人才能確定這個人是特殊的。

注意輸入那個字元。。。。。。

#include #include #include #include #include #include #include #include #include #define ll long long

using namespace std;

const int maxn = 2000 + 10;

const int maxm = 1000000 + 10;

const int inf = 0x3f3f3f3f;

int fa[maxn];

int r[maxn];

int error[maxn];

int n, m, k;

struct node q[maxn];

void init()

}int getf(int x)

return fa[x];

}int main()

/*for(int i = 0; i < m; i++) */

memset(error, -1, sizeof(error));

for(int i = 0; i < n; i++)

}else }}

int cnt = 0;

int a1, a2 = 0;

for(int i = 0; i < n; i++)

if(error[i] > a2) a2 = error[i];

}if(!cnt) printf("impossible\n");

else if(cnt > 1) printf("can not determine\n");

else printf("player %d can be determined to be the judge after %d lines\n", a1, a2);

}return 0;

}

HDU 1598 (列舉 並查集)

xx星有許多城市,城市之間通過一種奇怪的高速公路sars super air roam structure 超級空中漫遊結構 進行交流,每條sars都對行駛在上面的flycar限制了固定的speed,同時xx星人對 flycar的 舒適度 有特殊要求,即乘坐過程中最高速度與最低速度的差越小乘坐越舒服...

種類並查集(POJ 1703)

1703 find them,catch them 題目大意 有2個敵對幫派,輸入d a b表示a,b在不同幫派,輸入a a b表示詢問a,b是否是在乙個幫派。題解 因為並查集中的元素均是有聯絡的,否則也不會被合併到當前集合中。那麼我們就把這2個元素之間的關係量轉化為乙個偏移量,假設 x y 偏移量...

種類並查集(POJ1703)

圖學的有點自閉,再加上用到了並查集 模擬棧 搜尋,先補一下這些相對基礎的東西 跟普通並查集區別 1 陣列開兩倍 2 union set a n,b 和union set a,b n 3 判斷 find a find b 同隊 find a find b n 不同隊 不需要再 f a n f b n ...