[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 ...
随机推荐
- python 获取文件夹大小
__author__ = 'bruce' import os from os.path import join,getsize def getdirsize(dir): size=0l for (ro ...
- linux配置的问题
1 从系统设置-文本设置中把双拼删掉 2 通过sudo passwd root 修改root密码 3 通过su获取root权限 4 通过sudo pppoeconf输入宽带帐号密码 5 把更新源修改成 ...
- MC java 远程调试 plugin 开发
@ECHO OFF SET CATALINA_OPTS= -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,se ...
- mysql事务处理用法与实例详解
来源:转载 MySQL的事务支持不是绑定在MySQL服务器本身,而是与存储引擎相关1.MyISAM:不支持事务,用于只读程序提高性能 2.InnoDB:支持ACID事务.行级锁.并发 3.Berke ...
- 使用Intellij idea开发
使用IntelliJ IDEA开发SpringMVC网站(一)开发环境 使用IntelliJ IDEA开发SpringMVC网站(二)框架配置 使用IntelliJ IDEA开发SpringMVC网站 ...
- ContentProvider 增删改查通讯录
一.通讯录应用介绍 通讯录应用是Android自带的应用程序,我们看到此应用的时候,可能只认为这是一个应用,用数据库存储数据,但是实际上不是这样的. 通讯录是ContentProvider的应用,通讯 ...
- 技术英文单词贴--R
R redirect 重定向,改变方向 reference 参考,提及,引用 register 注册,登记,挂号 render 渲染 represent 代表,象征 route 路线,路由,通道 ro ...
- idhttp的用法
1)POST function PostMethod(http: TIDhttp; URL: string; Params: TStringList): string;var RespData: TS ...
- Sql Server 复制表
SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,fiel ...
- IOS 进度条与手势
//进度条#import "ViewController.h" @interface ViewController () { UIImageView* _animaImageV; ...