注意到随机一组贪心解得到的团的大小不小于$\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;
}
}
}

  

BZOJ2530 : [Poi2011]Party的更多相关文章

  1. BZOJ2530 [Poi2011]Party 【贪心】

    题目链接 BZOJ2530 题解 如果我们删去一对不连边的仍然存在的点的话,这对点肯定不同时在那个\(\frac{2}{3}n\)的团中,也就是说,每次删点至少删掉一个外点,至多删掉一个内点 那么我们 ...

  2. POI2011题解

    POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...

  3. 【BZOJ2530】[Poi2011]Party (xia)构造

    [BZOJ2530][Poi2011]Party Description 给定一张N(保证N是3的倍数)个节点M条边的图,并且保证该图存在一个大小至少为2N/3的团. 请输出该图的任意一个大小为N/3 ...

  4. BZOJ2527: [Poi2011]Meteors

    补一发题解.. 整体二分这个东西,一开始感觉复杂度不是很靠谱的样子 问了po姐姐,说套主定理硬干.. #include<bits/stdc++.h> #define ll long lon ...

  5. BZOJ2276: [Poi2011]Temperature

    2276: [Poi2011]Temperature Time Limit: 20 Sec  Memory Limit: 32 MBSubmit: 293  Solved: 117[Submit][S ...

  6. BZOJ2213: [Poi2011]Difference

    2213: [Poi2011]Difference Time Limit: 10 Sec  Memory Limit: 32 MBSubmit: 343  Solved: 108[Submit][St ...

  7. BZOJ2212: [Poi2011]Tree Rotations

    2212: [Poi2011]Tree Rotations Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 391  Solved: 127[Submi ...

  8. BZOJ 2212: [Poi2011]Tree Rotations( 线段树 )

    线段树的合并..对于一个点x, 我们只需考虑是否需要交换左右儿子, 递归处理左右儿子. #include<bits/stdc++.h> using namespace std; #defi ...

  9. bzoj 2217 [Poi2011]Lollipop 乱搞 贪心

    2217: [Poi2011]Lollipop Time Limit: 15 Sec  Memory Limit: 64 MBSec  Special JudgeSubmit: 383  Solved ...

随机推荐

  1. HXOI 2014 PSet 4 Day 1 一模04日1 题解

    1. 最小花费(money.pas/c/cpp) 问题描述 在n个人中,某些人的银行账号之间可以互相转账.这些人之间转账的手续费各不相同.给定这些人之间转账时需要从转账金额里扣除百分之几的手续费,请问 ...

  2. process vs thread

    process vs thread http://blog.csdn.net/mishifangxiangdefeng/article/details/7588727 6.进程与线程的区别:系统调度是 ...

  3. windows下批量删除文件

    FORFILES /P d:\www /D -7 /S /M ex*.log /C "cmd /c del @path" 删除d:\www目录下7天前ex*.log的所有文件 例子 ...

  4. Mobile first! Wijmo 5 + Ionic Framework之:Hello World!

    本教程中,我们用Wijmo 5 和 Ionic Framework实现一个Mobile的工程:Hello World. Ionic是什么? Ionic是一个HTML5框架.免费.开源,用于帮助生成hy ...

  5. sqlserver 常用语句

    1.查询表中的RID RID=RowID=(fileID:pageID:slotID) SELECT sys.fn_PhysLocFormatter(%%physloc%%) AS rid,* FRO ...

  6. Android 模拟器genymotion安装,eclipse 插件

    genymotion是一款号称速度最快性能最好的android模拟器,它基于Oracle VM VirtualBox.支持GPS.重力感应.光.温度等诸多传感器:支持OpenGL 3D加速:电池电量模 ...

  7. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  8. HttpHandler动态生成图片

    1.向服务器请求返回图片,浏览器是不知道服务上有这个图片的存在的,只是发出请求,接收请求,显示图片 string path = context.Server.MapPath("~/1.jpg ...

  9. KMP模式匹配

    http://www.cnblogs.com/wangguchangqing/archive/2012/09/09/2677701.html nextal[j+1]=next[j]+1 KMP算法的实 ...

  10. Man简单介绍

    转自:http://os.51cto.com/art/201312/425525.htm Linux系统提供了相对比较丰富的帮助手册(man),man是manual的缩写,在日常linux系统管理中经 ...