HDU 1704 Rank【传递闭包】
解题思路:给出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
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.
#include<stdio.h>
#include<string.h>
int d[505][505],a[505][505];
int main()
{
int ncase,n,m,i,j,k,sum,x,y;
scanf("%d",&ncase);
while(ncase--)
{
memset(d,0,sizeof(d));
sum=0;
scanf("%d %d",&n,&m);
while(m--)
{
scanf("%d %d",&x,&y);
d[x][y]=1;
} for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
{
if(d[i][k])
for(j=1;j<=n;j++)
d[i][j]=d[i][j]||(d[k][j]);
} for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(!(d[i][j]||d[j][i]))
sum++;
printf("%d\n",sum);
}
}
HDU 1704 Rank【传递闭包】的更多相关文章
- Rank HDU - 1704 【传递闭包水题】
there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellen ...
- HDU 1704 Rank
Rank Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 17046 ...
- hdu - 1704 Rank(简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1704 遇到标记过的就dfs,把隐含的标记,最后计数需要注意. #include <cstdio> # ...
- hdu 1704 Rank (floyd闭包)
Rank Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 1704 (Floyd 传递闭包)
Rank Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 1718 Rank
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1718 Rank Description Jackson wants to know his rank ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- P1888 三角函数
题目描述 输入一组勾股数a,b,c(a≠b≠c),用分数格式输出其较小锐角的正弦值.(要求约分.) 输入输出格式 输入格式: 一行,包含三个数,即勾股数a,b,c(无大小顺序). 输出格式: 一行,包 ...
- 谈谈javascript中原型继承
什么是继承?拿来主义:自己没有,别人有,把别人的拿过来使用或者让其成为自己的 如何实现继承的方式 原型继承 混入继承 经典继承 1. 混入继承 由于一个对象可以继承自任意的对象,即:o可以继承自对象o ...
- null和undifned的区别
null和undifned的区别 1 从类型方面:null的类型是对象,undified的类型是undified. 2 从定义方面:null是一个表示"无"的对象,转为数值时为0: ...
- win32应用禁止改变窗口大小方法
一种简单的处理方法是在调用CreateWindow函数时指定的窗口样式中去掉WS_THICKFRAME样式. 如果你使用的样式中已经包含该样式,例如WS_OVERLAPPEDWINDOW,我们可以將W ...
- BZOJ2179: FFT快速傅立叶 FFT实现高精度乘法
Code: #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...
- 粘包解决高端_Server
from socket import * #导入套接字模块的所有命令import subprocess #导入subprocess模块,用于执行命令行import struct #导入struck模块 ...
- JTree知识小点
创建一个新节点 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("新节点"); 被选中的节点 Default ...
- IOS - ImagePicker 连拍
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)sel ...
- CSS变量实用指南及注意事项
近年来,一些动态特性已经开始成为 CSS 语言本身的一部分. CSS变量 – 官方的术语为 "自定义属性" – 已经已经加入规范并且具有很好的浏览器支持,而 CSS mixins ...
- VUE:路由
VUE:路由 一.说明 1)官方提供的用来实现SPA的vue插件 2)github:https://github.com/vuejs/vue-router 3)中文文档:http://router.v ...