歸併 STL 洛谷 P1309 瑞士輪

2022-05-10 03:33:42 字數 632 閱讀 5346

樸素演算法每輪都sort會tle

所以要優化 用歸併

難點在於想明白為什麼是歸併

比賽過程中 

輸贏持續有序 

這是歸併的前提條件

所以才可以歸併

#include #include using namespace std;

const int maxn = 2e5 + 10;

struct team

arr[maxn], brr[maxn], crr[maxn];

bool cmp(team a, team b)

int main()

for(int i = 1; i <= 2 * n; i++)

sort(arr + 1, arr + 1 + (2 * n), cmp);

while(r--)

else

}merge(brr + 1, brr + tf, crr + 1, crr + tf, arr + 1, cmp); }

cout<

return 0;

}

洛谷 P1309 瑞士輪(歸併)

題意 一共2n個人 有乙個初始分數 進行k輪比賽,每輪比賽按當前得分排出名次,然後比賽按照第1名和第2名,第3和第4 第2n 1和2n進行 實力各不相同且實力大的總能獲勝 獲勝方加一分,失敗方分數不變。思路 一開始想在每輪比賽前用sort排序,算了下複雜度大概o n n logn n k 顯然不行。...

洛谷 P1309 瑞士輪 歸併

每一輪快排,超時 include include include include using namespace std class athlete athlete int id,int competence,int score id id competence competence score s...

洛谷P1309 瑞士輪

本題同樣是noip普及組第三題。因為太久沒有做過題目了,先從普及組開始練習吧。題目內容 很顯然想到的思路就是模擬,如下 include include include include using namespace std struct player bool cmp player a,player...