[ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than k friends in common, they will become friends in several days. Currently, there are totally n people in the country, and m friendship among them. Assume that any new friendship is made only when they have sufficient friends in common mentioned above, you are to tell how many new friendship are made after a sufficiently long time.
Input
There are multiple test cases.
The first lien of the input contains an integer T (about 100) indicating the number of test cases. Then T cases follow. For each case, the first line contains three integersn, m, k (1 ≤ n ≤ 100, 0 ≤ m ≤ n×(n-1)/2, 0 ≤ k ≤ n, there will be no duplicated friendship) followed by m lines showing the current friendship. The ith friendship contains two integers ui, vi (0 ≤ ui, vi < n, ui ≠ vi) indicating there is friendship between person ui and vi.
Note: The edges in test data are generated randomly.
Output
For each case, print one line containing the answer.
Sample Input
3
4 4 2
0 1
0 2
1 3
2 3
5 5 2
0 1
1 2
2 3
3 4
4 0
5 6 2
0 1
1 2
2 3
3 4
4 0
2 0
Sample Output
2
0
4
Author: ZHUANG, Junyuan
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest
题目大意:给定你n个点 然后给定m条边 如果2个不相连的点和其他不小于k个点都相连,那么它们两之间就产生一条新边 问你最后一共产生多少条新边
解题思路:纯暴力解法,每次重新开始计算是否可以建立新边,直至不能建立为止。[这种暴力解法的思路值得学习一下,暴力枚举,直到状态不再变化停止]
#include<iostream>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
int main(){
int T;
cin>>T;
int map[][];//存放关系的矩阵
while(T--){
memset(map,,sizeof(map));
int n,m,k;
cin>>n>>m>>k;
for(int i=;i<m;i++){
int u,v;
cin>>u>>v;
map[u][v]=;
map[v][u]=;
} bool ok=;
int num=;
while(ok){//纯暴解法,直至不能产生新边结束
ok=;
for(int i=;i<n-;i++){
for(int j=i+;j<n;j++)if(!map[i][j]){//遍历不相连的2点
int tot=;//计算公共相连的点数
for(int kk=;kk<n;kk++)
if(map[i][kk] && map[j][kk])
tot++;
if(tot>=k){//如果不小于k就相连
num++;
map[i][j]=map[j][i]=;
ok=;
}
}
}
} cout<<num<<'\n';
}return ;
}
[ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]的更多相关文章
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- F - Friends ZOJ - 3710(暴力)
题目链接:https://cn.vjudge.net/contest/280949#problem/F 题目大意:给你n个人,然后给你m个关系,每个关系输入t1, t2 .代表t1和t2是朋友关系(双 ...
- 暴力 ZOJ 1403 Safecracker
题目传送门 /* 暴力:纯暴力,在家水水 */ #include <cstdio> #include <cstring> #include <algorithm> ...
- [ACM_搜索] ZOJ 1103 || POJ 2415 Hike on a Graph (带条件移动3盘子到同一位置的最少步数 广搜)
Description "Hike on a Graph" is a game that is played on a board on which an undirected g ...
- ZOJ 2747 Paint the Wall(离散化+暴力)题解
题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...
- Friends (ZOJ - 3710)
Problem Alice lives in the country where people like to make friends. The friendship is bidirectiona ...
- [ACM_模拟] ZOJ 3713 [In 7-bit 特殊输出规则 7bits 16进制]
Very often, especially in programming contests, we treat a sequence of non-whitespace characters as ...
- [ACM_图论] ZOJ 3708 [Density of Power Network 线路密度,a->b=b->a去重]
The vast power system is the most complicated man-made system and the greatest engineering innovatio ...
- [ACM_动态规划] ZOJ 1425 Crossed Matchings(交叉最大匹配 动态规划)
Description There are two rows of positive integer numbers. We can draw one line segment between any ...
随机推荐
- html--第一章 基础知识总结
1--<body bgcolor="red">背景颜色 2--<body backgroud="back-ground.gif"> 背 ...
- java基础十一[远程部署的RMI](阅读Head First Java记录)
方法的调用都是发生在相同堆上的两个对象之间(同一台机器的Java虚拟机),如果想要调用另一台机器上的对象,可以通过Socket进行输入/输出. 远程过程调用需要创建出4种东西:服务器.客户端.服务器辅 ...
- POJ 1661 Help Jimmy LIS DP
http://poj.org/problem?id=1661 对板按高度排序后. dp[i][0]表示现在站在第i块板上,向左跑了,的状态,记录下时间和其他信息. O(n^2)LIS: 唯一的麻烦就是 ...
- Arduino 报错总结
Arduino出现avrdude: stk500_getsync(): not in sync: resp=0x00 )首先检查是否选择了合适的板子,选错主板型号也会造成上述错误 )重新安装驱动,换个 ...
- Python全栈之路3--set集合--三元运算--深浅拷贝--初识函数
一.上节课的重点回顾: 1.类名加括号其实就是执行类的__init__方法: 2.int a.创建方式 n1 = 123 #根据int类创建了一个对象 n2 = int(123) #根据int类创建一 ...
- iOS获取当前app的名称和版本号
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // ap ...
- golang使用interface来mock进行测试(来自dotGO2014)
源自于dotGO 2014的视频,讲述如何使用 interface 来mock 进行测试.. 可以FQ的同学自己观看,这里把重要的一些代码给截图搬到国内了 https://www.youtube.co ...
- [R] 回归拟合
如下示例 > fit <- lm(y~x, data = data01) > summary(fit) Call: lm(formula = data01$P ~ data01$M, ...
- JAVA基础之两种核心机制
突然之间需要学习Java,学校里学的东西早就忘记了,得用最短的时间把Java知识理顺,重点还是J2EE,毕竟所有的ava项目中95%都是J2EE,还是先从基础的J2SE学起吧....... 首先是了解 ...
- linux ps命令
名称:ps 使用权限:所有使用者 使用方式:ps [options] [--help] 说明:显示瞬间行程 (process) 的动态 参数: ps 的参数非常多, 在此仅列出几个常用的参数并大略介绍 ...