2018湖南大學校賽 B DSU

2021-08-20 08:00:50 字數 1183 閱讀 5374

簡略題意:

有n張牌 每張牌2面, 你每張牌只能選乙個面, 把這n張牌排序後從 最大能從1開始連續到多少會斷掉?

想法很棒棒啊。

首先把牌面看做一條邊,考慮一棵n大小的樹的情況,那麼可以使得其中n-1個點被選出來。如果這不是乙個樹,那麼這個圖里的任意節點都可以滿足。

為了讓答案更優,對於每個聯通塊,我們必然選擇每個聯通塊序號最小的n-1個點。

用並查集來維護,每次啟發式合併兩個聯通塊。

#define others

#ifdef poj

#include

#include

#include

#include

#include

#include

#include

#include

#include

#endif // poj

#ifdef others

#include

#endif // others

//#define file

#define all(x) x.begin(), x.end()

using

namespace

std;

#define eps 1e-8

const

double pi = acos(-1.0);

typedef

long

long ll;

typedef

unsigned

long

long ull;

void umax(int &a, int b)

void umin(int &a, int b)

int dcmp(double x)

void file()

namespace solver

int find(int x)

void solve() else

}for(int i = 1; i <= 10000; i++)

}int i = 0;

for(i = 1; i <= 10001; i++)

cout

<1;

}}/*

2 0 2

1 23 1

*/int main()

長安大學校賽 2017

a 水 include using namespace std int a 10 int main int ans 0 while x printf d n ans return 0 b 貪心,每遇到乙個字元,將其移動到合理的地方。include using namespace std typede...

湘潭大學校賽I

accepted 58 submit 349 time limit 5000 ms memory limit 65536 kb 作為一名即將畢業大學生,小明即將參加一系列的面試,每場面試都有乙個開始時間 si和乙個結束時間 ti。小明可以選擇參加面試或者放棄面試,但是遲到和早退是不允許的。每場面試對...

湖南大學程式設計競賽新生賽(重現賽)

1.從一堆糖果裡取奇數個或偶數個,誤以為是取奇數個糖果的一堆 2.tutu和dada各自一直只能取奇數個和偶數個,因為 and then buy candy alternately 誤認為只有第一輪才有限制,後面隨意 舉了幾組,發現只有當n 1,並且第乙個是偶數時才是dada贏 include us...