CF574B Bear and Three Musketeers 简单的图,暴力
来源:互联网 发布:app 是什么软件 编辑:程序博客网 时间:2024/06/05 00:29
要从一群人中选择三个,给出一系列数对(i,j)表示第i个人和第j个人认识
现在给出要求,要选3个人,首先他们三个需要互相认识,其次,他们每个人除去另两个之外还认识的人的数目作为他们自己的recognition值,要求三人的recognition值之和尽量小,求这个最小值
规模在4000人,纯暴搜当然不可以。
对于每对关系,建一个图,用数组G表示,两人i,j有朋友关系则G[i][j]=G[j][i]=1 没关系的值取0
然后可以暴搜了,筛掉三个人没有构成互相认识关系的取法,对每种符合要求的取法,各自的recognition值就是认识的人的总量减去2,即减去同时被选上的俩人。求recognition值之和,更新最小值
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<vector>#include<stack>#include<string>#include<cstdlib>#include<iomanip>#define maxn 100010//#define file//#define inf 9223372036854775808#define inf2 0x3f3f3f3f3f3f3f3fusing namespace std;int num;int pnum;int cnt[4010];int G[4010][4010];int main(){ scanf("%d %d",&num,&pnum); memset(G,0,sizeof(G)); memset(cnt,0,sizeof(cnt)); int a,b; int ans=0x3f3f3f3f; for(int i=0;i<pnum;i++) { scanf("%d%d",&a,&b); cnt[a]++; cnt[b]++; G[a][b]=1; G[b][a]=1; } for(int i=1;i<=num;i++) { for(int j=1;j!=i&&j<=num;j++) { if(!G[i][j])continue; for(int k=1;k!=i&&k!=j&&k<=num;k++) { if((G[i][k])&&(G[j][k])) { int tmp=cnt[i]+cnt[j]+cnt[k]-6; if(tmp<ans) { ans=tmp; //printf("***%d %d %d\n",i,j,k); } } } } } printf("%d\n",ans==0x3f3f3f3f? -1:ans);}
0 0
- CF574B Bear and Three Musketeers 简单的图,暴力
- Bear and Three Musketeers
- Bear and Three Musketeers
- B. Bear and Three Musketeers
- Bear and Three Musketeers CodeForces
- CodeForces 574B-Bear and Three Musketeers
- Codeforces 574B Bear and Three Musketeers
- Codeforces 574 B. Bear and Three Musketeers
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)
- CF#318-B - Bear and Three Musketeers-暴力寻找三元环
- CF#318 (Div. 2)B. Bear and Three Musketeers 暴力 复杂度分析
- Codeforces Round #318 574B Bear and Three Musketeers(模拟)
- Codeforces Round #318 B - Bear and Three Musketeers
- Codeforces Round #318-(B. Bear and Three Musketeers)
- Codeforces 574B Bear and Three Musketeers【思维】
- Codeforces Round #318 (Div. 2) B. Bear and Three Musketeers 位运算压缩
- 模拟赛#1补题 CodeForces 574B Bear and Three Musketeers(模拟判环)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)B Bear and Three Musketeers
- java 的接口使用
- java IO 刘 File 基础
- uva1585 - Score
- 【POJ1236】【tarjan】【SCC强连通】
- Android中关于空指针异常的解决办法
- CF574B Bear and Three Musketeers 简单的图,暴力
- android中所有颜色代码
- Leetcode231 Power of Two
- 求出1-100之间所有的素数(只能被1和它本身整除),要求每5个换行输出。
- http协议详解
- HDU 1016 dfs+回溯
- 文章标题
- iOS开发 顶部状态栏的隐藏
- scala实现设计模式之中介者模式