BZOJ2530 : [Poi2011]Party

注意到随机一组贪心解得到的团的大小不小于$\frac{N}{3}$的概率是很大的,所以一直随机下去,直到找到一组解即可,随机次数是常数级别的,所以复杂度为$O(n^2)$。

#include<cstdio>
#include<cstdlib>
#define N 3010
int n,m,i,j,k,a[N],del[N],fin[N];bool g[N][N];
inline void swap(int&a,int&b){int c=a;a=b;b=c;}
inline void read(int&a){char c;while(!(((c=getchar())>=‘0‘)&&(c<=‘9‘)));a=c-‘0‘;while(((c=getchar())>=‘0‘)&&(c<=‘9‘))(a*=10)+=c-‘0‘;}
int main(){
  read(n),read(m);
  while(m--)read(i),read(j),g[i-1][j-1]=g[j-1][i-1]=1;
  for(i=0;i<n;i++)a[i]=i;
  while(1){
    for(i=0;i<n;i++)swap(a[i],a[std::rand()%n]);
    for(i=0;i<n;i++)del[i]=0;
    for(k=i=0;i<n;i++)if(!del[i])for(k++,j=i+1;j<n;j++)if(!g[a[i]][a[j]])del[j]=1;
    if(k>=n/3){
      for(i=j=0;i<n;i++)if(!del[i])fin[j++]=a[i];
      for(i=0;i<n/3;i++)printf("%d ",fin[i]+1);
      return 0;
    }
  }
}

  

时间: 2024-10-10 09:43:30

BZOJ2530 : [Poi2011]Party的相关文章

BZOJ2212: [Poi2011]Tree Rotations

2212: [Poi2011]Tree Rotations Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 391  Solved: 127[Submit][Status] Description Byteasar the gardener is growing a rare tree called Rotatus Informatikus. It has some interesting features: The tree consists o

【BZOJ2216】[Poi2011]Lightning Conductor 决策单调性

[BZOJ2216][Poi2011]Lightning Conductor Description 已知一个长度为n的序列a1,a2,...,an.对于每个1<=i<=n,找到最小的非负整数p满足 对于任意的j, aj < = ai + p - sqrt(abs(i-j)) Input 第一行n,(1<=n<=500000)下面每行一个整数,其中第i行是ai.(0<=ai<=1000000000) Output n行,第i行表示对于i,得到的p Sample I

BZOJ2213: [Poi2011]Difference

2213: [Poi2011]Difference Time Limit: 10 Sec  Memory Limit: 32 MBSubmit: 343  Solved: 108[Submit][Status] Description A word consisting of lower-case letters of the English alphabet ('a'-'z') is given. We would like to choose a non-empty contiguous (

【BZOJ2529】[Poi2011]Sticks 贪心

[BZOJ2529][Poi2011]Sticks Description 给出若干木棍,每根木棍有特定的颜色和长度.问能否找到三条颜色不同的木棍构成一个三角形.(注意这里所说的三角形面积要严格大于0) 第一行给出一个整数k(3<=k<=50),表示颜色的种数.这k种颜色被标号为1至k.接下来k行,第i+1描述颜色为i的木棍的信息.首先一个整数Ni(1<=Ni<=10^6)表示颜色为i的木棍的数量.接下来Ni个整数,表示这Ni根木棍各自的长度.所有木棍的长度<=10^9.总木

整体二分-BZOJ2527【poi2011】meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 405 Solved: 160 [Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colo

【BZOJ 2527】 [Poi2011]Meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 405 Solved: 160 [Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colo

[BZOJ] 2276: [Poi2011]Temperature

2276: [Poi2011]Temperature Time Limit: 20 Sec  Memory Limit: 32 MBSubmit: 731  Solved: 334[Submit][Status][Discuss] Description The Byteotian Institute of Meteorology (BIM) measures the air temperature daily. The measurement is done automatically, an

2527: [Poi2011]Meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 1528  Solved: 556[Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for col

[Poi2011]Dynamite

[Poi2011]Dynamite 时间限制: 3 Sec  内存限制: 128 MB 题目描述 The Byteotian Cave is composed of  n chambers and n-1 corridors that connect them. For every pair of chambers there is unique way to move from one of them to another without leaving the cave. Dynamite