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. 开源项目Druid的提取SQL模板

    在数据库审计中,常常用到SQL模板,这样提取一次模板,下一次就不用对相同的模板的SQL进行相关操作.对此Druid提供相应的工具类进行SQL模板提取: package com.dbappsecurit ...

  2. CCNA基础知识摘录

    cisco设备的启动要点: 1.检测硬件(保存在rom) 2.载入软件(IOS)(保存在Flash) 3.调入配置文件(密码,IP地址,路由协议都保存在此)(此文件保存在NVRAM) 0x2102:正 ...

  3. 转:【深入Java虚拟机】之六:Java语法糖

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/18011009 语法糖(Syntactic Sugar),也称糖衣语法,是由英国计算机学家P ...

  4. 团队作业7---Alpha冲刺之事后诸葛亮

    一.设想与目标 1.我们的软件要解决什么问题? 我们的软件主要是帮助老师解决通过博客地址收集博客的相关信息来对学生对课程的认真与努力程度进行评定的问题,主要就是根据采集到的各项博客数据作为评分项,构建 ...

  5. 结对作业1----基于flask框架的四则运算生成器

    011.012结对作业 coding地址:https://coding.net/u/nikochan/p/2nd_SE/git 一.作业描述 由于上次作业我没有按时完成,而且庞伊凡同学编程能力超棒,所 ...

  6. One.1

    Github地址:https://github.com/zyp031502148/zyp1 解题思路: 看到数独这个题目的时候,我就想到了平时自己玩数独之后一开始怎么做的,可是发现那样的话需要先出一个 ...

  7. 【Alpha】Daily Scrum Meeting——Day4

    站立式会议照片 1.本次会议为第四次Meeting会议: 2.本次会议在大课间09:40,在图书馆一楼楼道召开,本次会议为30分钟讨论昨天的任务完成情况以及接下来的任务安排. 燃尽图 每个人的工作分配 ...

  8. 201521123104《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. (1)继承时子类将获得父类的属性与方法,并具有自身特有的属性与方法. (2)使用super还 ...

  9. 201521123118《java程序与设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容 2. 书面作业 1. 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synch ...

  10. hadoop-2.6.0源码编译

    运行hadoop环境时,常常会出现这种提示 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your plat ...