Friends (ZOJ - 3710)
Problem
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 integers n, 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 ithfriendship 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
题解:暴力遍历所有朋友直到不再出现新的朋友关系就可以了。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
int vis[110][110]; //用来判断是否是朋友关系
int main()
{
int n,i,j,m,t,k,ans,x,y,l;
while(scanf("%d",&t) != EOF)
{
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
memset(vis,0,sizeof(vis));
for(i=0; i<m; i++)
{
scanf("%d%d",&x,&y);
vis[x][y] = 1;
vis[y][x] = 1;
}
ans = 0;
m = 0;
while(1)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i==j||vis[i][j]) continue; // 如果是自己或者已经是朋友关系就不用判断了
x = 0;
for(l=0; l<n; l++)
{
if(vis[i][l]&&vis[j][l])
x++;
}
if(x>=k)
{
ans++;
vis[i][j] = vis[j][i] = 1;
}
}
}
if(m==ans) break; // 如果和上次循环的结果一样,就说明不会再增加新的朋友关系了,跳出循环就可以了
m = ans;
}
printf("%d\n",ans);
}
}
return 0;
}
Friends (ZOJ - 3710)的更多相关文章
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy
Information Entropy Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Information ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- POJ 2590 Steps (ZOJ 1871)
http://poj.org/problem?id=2590 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1871 题目大 ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
- 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematic ...
- Applications (ZOJ 3705)
题解:就是题目有点小长而已,可能会不想读题,但是题意蛮好理解的,就是根据条件模拟,计算pts.(送给队友zm. qsh,你们不适合训练了.) #include <iostream> #in ...
随机推荐
- kettle工具的介绍和使用
kettle详解(数据抽取.转换.装载) 原文地址链接:https://blog.csdn.net/qq_35731570/article/details/71123413 一:下载路径 当你要学 ...
- (四)Activiti之流程定义部署之ZIP方式和流程定义查询
一.流程定义部署之ZIP方式 上一章节我们使用classpath的方式加载流程定义文件,这里我们使用ZIP的方式. 1.1 用activiti插件生成bpmn和png图片之后,压缩到一个zip格式的压 ...
- JAVA的转义字符
一.常见的转义字符 转移字符对应的英文是escape character , 转义字符串(Escape Sequence) 字母前面加上捺斜线"\"来表示常见的那些不能显示的AS ...
- 3、java基础:抽象类与接口的区别
抽象类 我们都知道在面向对象的领域一切都是对象,同时所有的对象都是通过类来描述的,但是并不是所有的类都是来描述对象的.如果一个类没有足够的信息来描述一个具体的对象,而需要其他具体的类来支撑它,那么这样 ...
- eclipse调试之edit source lookup path解决方案
转自:https://blog.csdn.net/zkn_CS_DN_2013/article/details/48731133
- h5常见
Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面//一.HTML页面结构<meta name="viewport" content="widt ...
- 定义Java类实现字节流转字符流
package com.buaa.comparable; import java.io.BufferedReader;import java.io.File;import java.io.FileIn ...
- Computer Vision_18_Image Stitching:A survey on image mosaicing techniques——2013
此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...
- Linux Backup: Hard Disk Clone with "dd"
Most of Windows users may know "Norton Ghost". Norton Ghost is a backup software for har ...
- CentOS7.X 搭建LAMP
第一部分搭建LAMP基础环境 1.检查CentOS是否为7.x版本 2.安装LAMP中的apache,采用yum源方法安装 yum install httpd httpd-devel A ...