ZOJ 3710 Friends(暴力)
来源:互联网 发布:sql加一行合计 编辑:程序博客网 时间:2024/06/05 09:52
Description
Alice livesin the country where people like to make friends. The friendship isbidirectional and if any two person have no less than kfriends in common, they will become friends in severaldays. Currently, there are totally n peoplein the country, and m friendshipamong them. Assume that any new friendship is made only when they havesufficient friends in common mentioned above, you are to tell how many newfriendship are made after a sufficiently long time.
Input
Thereare multiple test cases.
Thefirst lien of the input contains an integer T (about 100) indicating the number of testcases. Then T casesfollow. 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 duplicatedfriendship) followed by mlines showingthe current friendship. The ith friendshipcontains two integers ui,vi (0 ≤ ui, vi < n, ui ≠ vi) indicating thereis friendship between person ui and vi.
Note: The edges in test data are generated randomly.
Output
For eachcase, 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
这题意思是有n个人,其中有m对朋友关系,其中不认识的两个人要成为朋友的条件是他们有至少k个共同的朋友,问最后能有多少对新朋友。这题可以用图论解决,使用矩阵储存两个人之间的关系(1表示朋友关系,0表示不认识),然后遍历整个矩阵,寻找不认识的人的共同朋友,并判断他们是否能成为新朋友,若能,则关系改为1,再重新遍历矩阵。
#include <iostream>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m,k;
int P[105][105]={0};
cin>>n>>m>>k;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
P[u][v]=1;
P[v][u]=1;
}
int sum=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
int cnt=0;
if(i!=j&&P[i][j]==0)
{
for(int s=0;s<n;s++)
if((P[i][s]==1)&&(P[j][s]==1))
cnt++;
if(cnt>=k)
{
sum++;
P[i][j]=1;P[j][i]=1;
i=-1;
break;
}
}
}
}
cout<<sum<<endl;
}
return 0;
}
- ZOJ 3710 Friends(暴力)
- ZOJ 3710 Friends 暴力
- ZOJ 3710Friends(暴力)
- ZOJ Friends(暴力)
- ZOJ Problem Set - 3710 Friends(暴力)
- ZOJ 3710 Friends(暴力或map)
- 带技巧的暴力-ZOJ 3710 [Friends
- ZOJ-3710-Friends【10th浙江省赛】【暴力】
- zoj 3710 Friends(数学)
- ZOJ 3710 Friends(枚举)
- Friends (暴力枚举)
- ZOJ 3710 Friends(数学啊 )
- ZOJ-3710(Friends)
- zoj 3710 Friends
- zoj 3710 Friends
- zoj 3710 Friends
- Friends zoj 3710
- ZOJ 3710 Friends
- Tomcat启动正常,但Debug模式下无法启动
- 分布式应用程序协调服务zookeeper在.NET平台上的使用
- 【解决CSerialPort 串口类不能连续发送的问题】
- 日经春秋 20150324
- VC++ UDP通信程序
- ZOJ 3710 Friends(暴力)
- [Leetcode] 64. Minimum Path Sum
- [IOS 开发] 为UIImage 绘制 毛玻璃效果
- Android用程序在桌面创建app快捷方式
- RFID理论之基础知识结构整理
- Kinect 摄像头范围介绍和玩家舒适距离实测
- 格式化数字加逗号
- snort规则编写简述
- 根据资源名获取资源 id