Friends


Time Limit: 2 Seconds     
Memory Limit: 65536 KB


Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less thank friends in common, they will become friends in several days. Currently, there are totallyn 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. ThenT cases follow. For each case, the first line contains three integers
n, m, k (1 ≤ n ≤ 100, 0 ≤ mn×(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 integersui, vi (0 ≤ui, vi
<n, ui ≠ vi) indicating there is friendship between personui 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

大概思路:

1,数学方法?

2,二进制求交集+搜索+减枝?

3,暴力枚举?

大部分人用的floyd思想递推 :

i认识x,j认识x,那么i就有可能和j是朋友 ,找到i认识j的路径(x数)多等于k即可,如果可以认识,我们动态建路即可









对floyd的理解

for(k=1;k<=n;k++)

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(...)...

其中k为最对循环次数,我们可以改成:

while(上一次有更新)

{

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

if(...)...+标记更新

}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<memory.h>
using namespace std;
bool map[101][101];
int n,m,k,ans;
void _update()
{
ans=0;
memset(map,false,sizeof(map));
}
void _in()
{
int x,y;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<m;i++){
scanf("%d%d",&x,&y);
map[x][y]=map[y][x]=true;
}
}
void _solve()
{
bool temp=true;
while(temp)
{
temp=false;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
if(map[i][j]) continue;
int cnt=0;
for(int f=0;f<n;f++)
if(map[i][f]&&map[j][f])
cnt++;
if(cnt>=k) {
ans++;
map[i][j]=map[j][i]=true;
temp=true;
}
}
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
_update();
_in();
_solve();
}
}

zoj3710 friends(floyd变形)的更多相关文章

  1. UVA10048 Audiophobia[Floyd变形]

    UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...

  2. POJ2253——Frogger(Floyd变形)

    Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...

  3. hdu 1596(Floyd 变形)

    http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...

  4. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  5. Frogger(floyd变形)

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  6. UVa 10048 (Floyd变形) Audiophobia

    题意: 给一个带权无向图,和一些询问,每次询问两个点之间最大权的最小路径. 分析: 紫书上的题解是错误的,应该是把原算法中的加号变成max即可.但推理过程还是类似的,如果理解了Floyd算法的话,这个 ...

  7. find the mincost route(floyd变形 无向图最小环)

    Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  8. hdu1569find the safest road(floyd变形求最大安全值)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

随机推荐

  1. mysql创建字段非空NOT NULL的好处

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt338 很多表都包含可为 NULL (空值) 的列,即使应用程序井不需要保存 ...

  2. (八)、vpn-pptp部署

    中小型规模网站集群架构:VPN-PPTP : 矮哥linux运维群:93324526 前言: 你想管理机器吗? 你想更安全吗? 请安装VPN吧 部署 1.查看系统是否支持PPP [root@oldbo ...

  3. Windows10 VS2015下分别编译libevent 32位和64位库

    Libevnt 在Windows10 VS2015下分别编译32位和64位库 直接上王道 libevent代码地址: https://github.com/libevent/libevent git ...

  4. 展示博客(beta)

    1.基本介绍 团队成员简介 a.王婧:http://www.cnblogs.com/xmwj/ b.柯怡芳:http://www.cnblogs.com/keyi123/ c.陈艺菡:http://w ...

  5. 201521123083《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 1. 代码阅读:Child压缩包内源代码 1.1 com.par ...

  6. 英语词典Alpha版本发布说明

    Alpha版本发布说明 功能: ·简洁的应用界面,不被无良的广告弹窗影响  ·功能直接,在需要查词时及时出现,没有每日一句精选文章等杀了你的流量,在学习过程中更加专注! ·采用金山词霸API,提供发音 ...

  7. 201521123114《Java程序设计》第9周学习总结

    1. 本章学习总结 2. 书面作业 Q1. 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 经常出现的异常 ...

  8. JAVA课程设计+五子棋(团队博客)

    JAVA课程设计 利用所学习的JAVA知识设计一个五子棋小游戏 1.团队名称.团队成员介绍(菜鸟三人组) 杨泽斌[组长]:201521123049 网络1512 叶文柠[组员]:20152112305 ...

  9. java数据类型与二进制

    在java中 Int 类型的变量占 4个字节 Long 类型的变量占8个字节 一个程序就是一个世界,变量是这个程序的基本单位. Java基本数据类型 1.        整数类型 2.        ...

  10. logback:用slf4j+logback实现多功能日志解决方案

    slf4j是原来log4j的作者写的一个新的日志组件,意思是简单日志门面接口,可以跟其他日志组件配合使用,常用的配合是slf4j+logback,无论从功能上还是从性能上都较之log4j有了很大的提升 ...