Cow Contest POJ - 3660 (floyd 传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors.
The contest is conducted in several head-to-head rounds, each between two cows. If cow A has a greater skill level than cow B (1 ≤ A ≤ N; 1 ≤ B ≤ N; A ≠ B), then cow A will always beat cow B.
Farmer John is trying to rank the cows by skill level. Given a list the results of M (1 ≤ M ≤ 4,500) two-cow rounds, determine the number of cows whose ranks can be precisely determined from the results. It is guaranteed that the results of the rounds will not be contradictory.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..M+1: Each line contains two space-separated integers that describe the competitors and results (the first integer, A, is the winner) of a single round of competition: A and B
Output
* Line 1: A single integer representing the number of cows whose ranks can be determined
Sample Input
5 5
4 3
4 2
3 2
1 2
2 5
Sample Output
2 题意:n个人,m个关系,每个关系(a b)告诉你,a比b水平高,问你最后有多少人水平是可以确定的。
思路:刚开始一开这题意就莽拓扑排序,后来发现不对,(想着如果入队多个,说明无序,入队一个就有序,简直睿智)
其实是用floyd计算传递闭包,最后看对每个人是否关系都确定了。 (因为我图中只记录了,谁比谁等级高,所以闭包出来,也只有该点是否比其他点等级高,例如 maps【a】【b】,显然缺少一种别点比他高的情况,其实就是maps【b】【a】)
#include<cstdio>
#include<iostream> int maps[][]; int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int j=; j<=m; j++)
{
int u,v;
scanf("%d%d",&u,&v);
maps[u][v] = ;
}
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
maps[i][j] |= maps[i][k] && maps[k][j];
}
}
}
int num=n;
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// {
// printf("%d ",maps[i][j]);
// }
// puts("");
// }
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(j == i)continue;
if(!maps[i][j] && !maps[j][i])
{
num--;
break;
}
}
}
printf("%d\n",num);
}
Cow Contest POJ - 3660 (floyd 传递闭包)的更多相关文章
- Cow Contest POJ - 3660 floyd传递闭包
#include<iostream> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int f[N][N]; ...
- POJ 3660 Floyd传递闭包
题意:牛有强弱,给出一些牛的强弱的胜负关系,问可以确定几头牛的排名. 思路: Floyd传递闭包 // by SiriusRen #include <bitset> #include &l ...
- Cow Contest POJ - 3660
题意 有n(1<=n<=100)个学生参加编程比赛. 给出m条实力信息.(1<=M<=4500) 其中每一条的格式为 A B (1<=A<=N,1<=B< ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset
1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 891 Solved: 590 ...
- 图论---POJ 3660 floyd 算法(模板题)
是一道floyd变形的题目.题目让确定有几个人的位置是确定的,如果一个点有x个点能到达此点,从该点出发能到达y个点,若x+y=n-1,则该点的位置是确定的.用floyd算发出每两个点之间的距离,最后统 ...
- POJ 3275 Floyd传递闭包
题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...
- POJ 3660 cow contest (Folyed 求传递闭包)
N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
随机推荐
- Supervisor的安装以及使用
1.supervisor的介绍 Supervisor 是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统,通过配置可以实 ...
- CentOS下RPM方式安装MySQL5.6(转载)
之前的项目全都在windows系统环境下部署的,这次尝试在Linux系统环境下部署,于是这次我们组织在7台主机上安装了JDK.Maven.Jboss其中一台安装了Mysql,并将局域网配置好,终于大功 ...
- ps切图技巧
步骤1: ps打开psd文件 步骤2: 点击移动工具,观察左上角的自动选择是否有勾选 ,如果没有最好勾选,对应的选项有图层和组,善于切换这个功能能够有效快速的找到你要的区域 步骤3: 找到要切图的元素 ...
- springboot格式化时间
使用@RestController注解,返回的java对象中若含有date类型的属性,则默认输出为TIMESTAMP时间戳格式,可以在配置文件加入下面配置 spring.jackson.date-fo ...
- 一个账户接管几乎所有阿里巴巴网站(CSRF漏洞+WAF绕过)
场景 文章是关于某些客户端漏洞导致几个阿里巴巴网站的帐户被接管. 条件 TL;DR 必要条件,例如JSONP,某些浏览器处理cookie等行为. 攻击原理 大多数阿里巴巴的网站加载并执行外部JavaS ...
- 【easy】268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- JSSDK获取用户地理位置信息
复制一份JSSDK环境,创建一份index.html文件,结构如图7.1所示. 图7.1 7.1节文件结构 在location.js中,封装“getLocation”接口,如下: 01 wxJSS ...
- XPath Helper使用教程
下载地址 百度网盘下载密码:yuuv下载完成后选择保留 安装 在导航栏中输入chrome://extensions:将.crx文件拖拽到扩展程序页面中,勾选已启用按钮. 使用 重启浏览器,快捷键CTR ...
- lua post参数获取,参数截断
post 请求头: a.application/x-www-form-urlencoded 普通表单提交 b.multipart/form-data 含有文件的表单,二进制上传 c.applicati ...
- 二级导航 js
$(function(){ $(".classify dl dd").mouseover(function(){ $(this).addClass("on"); ...