[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 ...
随机推荐
- Web前端之CSS_day3-4
1.行高 1.1 初始行高 行高=文字大小+上间距+下间距 默认文字大小:16px 默认文字行高:18px 注意:行高=盒子的高度,可以让文字垂直居中显示 1.2 行高单位 a. px 行高设置多少就 ...
- hdu 2196 computer
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2.Mybatis入门程序(单表的增删改成)
这里讲的单表的增删改查,是由mapper代理的增删改查,先来看看步骤: 1.jar包的导入 2.配置全局的配置文件 3.建立接口 4.编写mapper.xml 5.测试 工程结构:这个你们自己可以调整 ...
- mysql - 最小缺失值查询
初始化数据 DROP TABLE IF EXISTS X; CREATE TABLE X( a INT UNSIGNED PRIMARY KEY, b ) NOT NULL )ENGINE=INNOD ...
- sqlserver巧用row_number和partition by分组取top数据
SELECT * FROM( SELECT orderid,createtime, ROW_NUMBER() over(PARTITION by orderid order by createtime ...
- ffmpeg未整理好,有时间整理下
v 容器(Container) v 容器就是一种文件(封装)格式,比如flv.mkv.ts.mp4.rmvb.avi等.包含下面5种流以及文件头信息. v 流(Stream) v 是一种视频数 ...
- poj 3264 Balanced Lineup (RMQ)
/******************************************************* 题目: Balanced Lineup(poj 3264) 链接: http://po ...
- protocol buffers的使用示例[z]
[http://blog.csdn.net/zhu_xun/article/details/19397081] protocol buffers的使用示例 如果不了解protocol buffers, ...
- zabbix使用sendEmail发送邮件报警
sendEmail是一个轻量级,命令行的SMTP邮件客户端.如果你需要使用命令行发送邮件,那么sendEmail是非常完美的选择:使用简单并且功能强大.这个被设计用在php.bashperl和web站 ...
- BIEE 11g学习
biee 11g学习1. 创建资料档案库文件(RPD) 文件数据库 1.1 创建数据源连接 运行Net Manager 用于BIEE的数据库服务 1.2 模型的建立 1.运行o ...