hdu6152-CCPC网络赛&思维&拉姆齐定理-Friend-Graph
来源:互联网 发布:淘宝客联盟如意投 编辑:程序博客网 时间:2024/05/22 04:36
http://acm.hdu.edu.cn/showproblem.php?pid=6152
比赛的时候理解错题意了,wa了好多发。
想在图中找到 完全图并且去掉。。
后来发现如果存在一个非常大的完全图,那么任意枚举这个图中的三个点,也能得到相同的结果。。。
所以就用的枚举。。 枚举三个点是否相互认识或者 相互不认识。
开始吃了mle的亏,用的bitset设置的。
第一次听说 拉姆齐定理。
每6个人中至少有三个人认识或者不认识。
#include <iostream>#include <bits/stdc++.h>using namespace std;/* 判断等于0的个数,和dengyu mde dushu*/int Scan(){ int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //判断正负 flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数 res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9' ) res = res * 10 + ch - '0'; return flag ? -res : res;}const int maxn=3003;vector<int>k;int du[maxn];bool vis[maxn];int gg[3003];bitset<3003>s[maxn];int main(){ int t,m,x; scanf("%d",&t); while(t--){ for(int i=0;i<maxn;i++) s[i].reset(); scanf("%d",&m); bool flag=false; memset(vis,false,sizeof(vis)); for(int i=0;i<m-1;i++){ for(int j=i+1;j<m;j++){ x=Scan(); if(x){ s[i].set(j); s[j].set(i); vis[i]=true; vis[j]=true; } }} //if(s[2].test(1)) puts("!"); for(int i=0;i<m&&!flag;i++){ for(int j=0;j<m&&!flag;j++){ for(int x=j+1;x<m&&!flag;x++){ if(i==j||j==x||x==i)continue; if(vis[i]&&vis[j]&&vis[x]&&!s[i].test(j)&&!s[i].test(x)&&!s[j].test(x)) { //cout<<i<<j<<x<<endl; flag=true;break;} } } } //if(flag) // cout<<"!!"<<endl; for(int i=0;i<m&&!flag;i++){ //if(s[i].count()<2) continue; //cout<<"!"<<endl; for(int j=0;j<m&&!flag;j++){ //cout<<j<<endl; for(int x=j+1;x<m&&!flag;x++){ if(i==j||j==x||x==i)continue; if(vis[i]&&vis[j]&&vis[x]&&s[i].test(j)&&s[i].test(x)&&s[j].test(x)) { //cout<<i<<j<<x<<endl; flag=true;break;} } } } if(!flag) puts("Great Team!"); else{ puts("Bad Team!"); } } return 0;}
附赠大佬的拉姆齐证明。
在组合数学上,拉姆齐(Ramsey)定理,又称拉姆齐二染色定理,是要解决以下的问题:要找这样一个最小的数 n,使得 n 个人中必定有 k 个人互相认识或 k 个人互不相识。
这个定理以弗兰克·普伦普顿·拉姆齐命名,1930年他在论文On a Problem in Formal Logic(《形式逻辑上的一个问题》)证明了R(3,3)=6。
证明:在一个 n = 6的完全图内,每边涂上红或蓝色,必然有一个红色的三角形或蓝色的三角形。
任意选取一个端点P,它有5条边和其他端点相连。
根据鸽巢原理,5条边的颜色至少有3条相同,不失一般性设这种颜色是红色。
在这3条边除了 P以外的3个端点,它们互相连结的边有3条。
若这3条边中任何一条是红色,这条边的两个端点和 P相连的2边便组成一个红色三角形。
若这3条边中任何一条都不是红色,它们必然是蓝色,因此,它们组成了一个蓝色三角形。
红色-有边
蓝色-无边
于是得证。
阅读全文
0 0
- hdu6152-CCPC网络赛&思维&拉姆齐定理-Friend-Graph
- hdu6152 Friend-Graph (2017 ccpc 网络赛 (暴力 + 一个神奇的定理)
- HDU6152 Friend-Graph(拉姆齐定理)
- hdu6152 Friend-Graph CCPC网赛1003 Ramsey定理
- hdu6152(拉姆齐(Ramsey)定理) Friend-Graph
- ccpc网络赛Friend-Graph
- [ccpc网络赛]Friend-Graph
- HDU6152 Friend-Graph(拉姆齐定理,2017中国大学生程序设计竞赛
- 2017CCPC网络赛 Friend-Graph(暴力、拉姆齐(Ramsey)定理)
- HDU6152 Friend-Graph 数学|签到|Ramsey定理
- 2017 ccpc 网络赛 Friend-Graph
- hdu5152.Friend-Graph(CCPC网络赛)
- 2017ccpc网络赛 1003Friend-Graph
- HDU6152 Friend-Graph【模拟】
- hdu6152 Friend-Graph
- HDU6152-Friend-Graph
- 2017ccpc网络赛——Friend-Graph
- 2017CCPC网络选拔赛1003Friend-Graph
- Jobdu1444 More is better (并查集)
- JAVA单例设计模式简析
- PAT_A 1042. Shuffling Machine (20)
- NOIP2014无线发射器选址
- 2017年8月18日 星期五
- hdu6152-CCPC网络赛&思维&拉姆齐定理-Friend-Graph
- dubbo为什么用到了zookeeper
- C++, Java和C#的编译、链接过程解析
- 2017年8月19日 星期六
- php的max_execution_time和php-fpm的request_terminate_timeout的详解
- shell判断字符串包含关系的三种方法
- Python实现简单orm
- 交换排序——冒泡排序
- HDU Friend-Graph(离散数学)