zoj3710 friends(floyd变形)
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 ≤ 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 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变形)的更多相关文章
- UVA10048 Audiophobia[Floyd变形]
UVA - 10048 Audiophobia Consider yourself lucky! Consider yourself lucky to be still breathing and h ...
- POJ2253——Frogger(Floyd变形)
Frogger DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fi ...
- hdu 1596(Floyd 变形)
http://acm.hdu.edu.cn/showproblem.php?pid=1596 find the safest road Time Limit: 10000/5000 MS (Java/ ...
- hdu 1217 (Floyd变形)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) ...
- Frogger(floyd变形)
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- UVa 10048 (Floyd变形) Audiophobia
题意: 给一个带权无向图,和一些询问,每次询问两个点之间最大权的最小路径. 分析: 紫书上的题解是错误的,应该是把原算法中的加号变成max即可.但推理过程还是类似的,如果理解了Floyd算法的话,这个 ...
- find the mincost route(floyd变形 无向图最小环)
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu1569find the safest road(floyd变形求最大安全值)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 4034 Graph(Floyd变形——逆向判断)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...
随机推荐
- Ubuntu操作系统下安装JDK、tomcat、mysql
1.先从安装虚拟机开始 01.首先打开VMware虚拟机. 02.然后,进入home主页,点击"create a New Virtual Machine"一栏,就会弹出一个 ...
- nrm的安装 、定义和用法
因为npm包管理工具是属于国外的,所以在中国使用它下载东西的时候比较慢.这时我们就想用国内的淘宝镜像.也有别的,所以当你想切换下载源的时候就会用到nrm了. ###首先,nrm是什么呢? 开发的npm ...
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.26
2017.04.26 天气热. 时间:上午 9:35 ---10:10分 地点:陆大304实验室 会议内容:今天将昨天的的一些问题进行了讨论,以及针对助教提出的问题进行了分析,是因为我们昨天经过讨论后 ...
- 201521123096《Java程序设计》第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 (1)clone方法 1.1 Object ...
- 201521123067 《Java程序设计》第14周学习总结
201521123067 <Java程序设计>第14周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 Q1. MySQL数 ...
- 201521123059 《Java程序设计》第十周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 多线程的相关理解图: 2. 书面作业 本次PTA作业题集异常.多线程 Q1:finally 题目4-2 1. ...
- Java课程设计——计算器
1.团队课程设计博客链接 http://www.cnblogs.com/yuanj/p/7072137.html 2.个人负责模块或任务说明 确定课题并进行任务分工 编写计算器删除,清零,清空,小数点 ...
- 201521123050 《Java程序设计》第11周学习总结
1. 本周学习总结 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synchronized修饰方法实现互斥同步访问,还 ...
- animation实现动画效果
CSS3 animation 属性 CSS 参考手册 实例 使用简写属性,将动画与 div 元素绑定: div { animation:mymove 5s infinite; -webkit-anim ...
- eclipse: eclipse导入工程出现大红叹号
总结: 问题原因:工程中classpath中指向的包路径错误 解决办法:到BUILDPATH CONFIG````中,liberaies中 出现红色叉号的包为路径错误的包.到classpath中修改相 ...