[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 ...
随机推荐
- (八) 一起学 Unix 环境高级编程 (APUE) 之 信号
. . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...
- iOS 设置 文字和 图片的位置
1.我最开始实现这个采用的方法:重新自定义一个view,然后有两个属性label和imageView,然后设置位置布局,再添加单击手势,用代理回传点击方法. 2.第二种方法:自定义一个Button继承 ...
- [jQuery]最新的 3.0 已发布
可以从 https://code.jquery.com/jquery/#jquery-all-1.x 找到历史版本 1.12.4 是支持 IE6 - 8 的最高版本. 下载地址 http://file ...
- HTTP协议-引自孤傲苍狼博客
一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...
- linux 下部署 kafka
参考文章 http://www.cnblogs.com/sunxucool/p/4459020.html http://www.cnblogs.com/oftenlin/p/4047504.html ...
- canvas事件
canvas的事件只能监听在canvas标签上,而不嗯那个想其他dom元素那样,所以针对canvas里面的图形监听事件是比较麻烦的. 通过isPointInPath(x,y); 这个方法用于判断某一 ...
- sql sever 2008修改数据类型
如果是新表,直接在表中修改: 如果不是新表,则须sql语句修改 附sql语句 alter table 表名 alter column 列名 新的数据类型
- Android -- The Manifest File
Before the Android system can start an app component, the system must know that the component exists ...
- Oracle中的带参数的视图--我们致力于打造人力资源软件
创建包和包体 create or replace package pkg_pv is procedure set_pv(pv varchar2); function get_pv return var ...
- css3的学习笔记1
一. 边框 1. border-color border-color是设置边框的颜色.包括border-top-color,border-left-color,border-right-colo ...