解题思路:给出n个选手,m场比赛,问不能判断胜负的询问最多有多少种

用传递闭包即可 但是如果直接用3重循环会超时 在判断d[i][j]=d[i][k]||d[k][j]是否连通的时候 可以加一个if语句判断一下d[i][k]是否为1,为1再进行第三重循环,不为1则不进行第三次循环

反思:例如询问 3和1,1和3是相同的情况,所以最后判断的时候,只需要判断上三角矩阵即可。

Rank

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1134    Accepted Submission(s): 429

Problem Description
there are N ACMers in HDU team. ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers will meet each other at two matches, means between two ACMers there will be at most one match). lcy also asks"Who is the winner between A and B?" But sometimes you can't answer lcy's query, for example, there are 3 people, named A, B, C.and 1 match was held between A and B, in the match A is the winner, then if lcy asks "Who is the winner between A and B", of course you can answer "A", but if lcy ask "Who is the winner between A and C", you can't tell him the answer. As lcy's assistant, you want to know how many queries at most you can't tell lcy(ask A B, and ask B A is the same; and lcy won't ask the same question twice).
 
Input
The input contains multiple test cases. The first line has one integer,represent the number of test cases. Each case first contains two integers N and M(N , M <= 500), N is the number of ACMers in HDU team, and M is the number of matchs have been held.The following M lines, each line means a match and it contains two integers A and B, means A wins the match between A and B.And we define that if A wins B, and B wins C, then A wins C.
 
Output
For each test case, output a integer which represent the max possible number of queries that you can't tell lcy.
 
Sample Input
3 3 3 1 2 1 3 2 3 3 2 1 2 2 3 4 2 1 2 3 4
 
Sample Output
0 0 4

Hint

in the case3, if lcy ask (1 3 or 3 1) (1 4 or 4 1) (2 3 or 3 2) (2 4 or 4 2), then you can't tell him who is the winner.

  1. #include<stdio.h>
  2. #include<string.h>
  3. int d[505][505],a[505][505];
  4. int main()
  5. {
  6. int ncase,n,m,i,j,k,sum,x,y;
  7. scanf("%d",&ncase);
  8. while(ncase--)
  9. {
  10. memset(d,0,sizeof(d));
  11. sum=0;
  12. scanf("%d %d",&n,&m);
  13. while(m--)
  14. {
  15. scanf("%d %d",&x,&y);
  16. d[x][y]=1;
  17. }
  18.  
  19. for(k=1;k<=n;k++)
  20. for(i=1;i<=n;i++)
  21. {
  22. if(d[i][k])
  23. for(j=1;j<=n;j++)
  24. d[i][j]=d[i][j]||(d[k][j]);
  25. }
  26.  
  27. for(i=1;i<=n;i++)
  28. for(j=i+1;j<=n;j++)
  29. if(!(d[i][j]||d[j][i]))
  30. sum++;
  31. printf("%d\n",sum);
  32. }
  33. }

  

HDU 1704 Rank【传递闭包】的更多相关文章

  1. Rank HDU - 1704 【传递闭包水题】

    there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...

  2. HDU 1704 Rank

    Rank Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 17046 ...

  3. hdu - 1704 Rank(简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...

  4. hdu 1704 Rank (floyd闭包)

    Rank Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. hdu 1704 (Floyd 传递闭包)

    Rank Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线

    hdu 1811 Rank of Tetris Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. hdu 1718 Rank

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1718 Rank Description Jackson wants to know his rank ...

  8. hdu 1811 Rank of Tetris - 拓扑排序 - 并查集

    自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...

  9. HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)

    Rank of Tetris Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. ASP.NET MVC+Bootstrap分页Helper

    <div class="pagination"> <ul> //************分页HTML********* </ul> </d ...

  2. <video> controlsList

    Audio/Video Updates in Chrome 58 <video controls controlsList="nofullscreen nodownload norem ...

  3. CSS3中的2D和3D转换知识介绍

    一  2D转换 转换是CSS3中具有颠覆性的特征之一,可以实现元素的位移.旋转.变形.缩放,甚至支持矩阵方式,配合即将学习的过渡和动画知识,可以取代大量之前只能靠Flash才可以实现的效果. 1.移动 ...

  4. NGUI 按钮点击事件的两种绑定形式

    面板属性栏绑定 写一个脚本,定义一个Public的方法 Notify中选择物体时,选中自己 然后就可以选择通知到写的那个脚本的里边的public方法 代码绑定 创建一个代码文件,挂载到按钮对象上 代码 ...

  5. Python多线程原理与实现

    Date: 2019-06-04 Author: Sun Python多线程原理与实战 目的: (1)了解python线程执行原理 (2)掌握多线程编程与线程同步 (3)了解线程池的使用 1 线程基本 ...

  6. iproute2+tc notes

    iproute2+tc notes The iproute2+tc package allows access to the variety of neat new networking featur ...

  7. 百度api使用说明

    .初始化地图,并设置地图中心点 复制代码 https://www.cnblogs.com/zqzjs/p/5293698.html var map = new BMap.Map("allma ...

  8. 《Exception》第八次团队作业:Alpha冲刺(大结局)

    一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1.掌握软件测试基础技术.2.学习迭代式增量软 ...

  9. 2019-03-18 Python time 将2015年11月20日转换为2015-11-20

    #ReportingDate = soup.select('body > div.main > div > div.ctr > div.recruit > ul > ...

  10. python--(常用模块-3-正则表达式)

    python--(常用模块-3-正则表达式) 正则表达式是对字符串操作的⼀种逻辑公式. 我们⼀般使⽤正则表达式对字符串进⾏匹 配和过滤. 使⽤正则的优缺点: 优点: 灵活, 功能性强, 逻辑性强. 缺 ...