BZOJ2530 [Poi2011]Party 【贪心】
题目链接
题解
如果我们删去一对不连边的仍然存在的点的话,这对点肯定不同时在那个\(\frac{2}{3}n\)的团中,也就是说,每次删点至少删掉一个外点,至多删掉一个内点
那么我们要删掉团外的点最多使用\(\frac{1}{3}n\)个团内的点就可以了,剩下的至少\(\frac{1}{3}n\)个点就在一个团内
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 3005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int G[maxn][maxn],vis[maxn],n,m;
int main(){
n = read(); m = read(); int a,b;
while (m--){
a = read(); b = read();
G[a][b] = G[b][a] = true;
}
int E = n / 3;
for (int i = 1; i <= n; i++){
if (vis[i]) continue;
for (int j = i + 1; j <= n; j++){
if (vis[j] || G[i][j]) continue;
//printf("(%d,%d)\n",i,j);
vis[i] = vis[j] = true;
break;
}
}
int cnt = 0;
REP(i,n){
if (!vis[i]) printf("%d ",i),cnt++;
if (cnt >= E) break;
}
return 0;
}