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 ...
随机推荐
- 实验二 Java面向对象程序设计 20175301李锦然实验报告
实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计 ...
- JavaScript之iframe页面间通信
[1] iframe父子页面间通信 1.相互调用对方的方法 |> 子级页面调用父级页面 window.parent.父级页面方法(args) |> 父级页面调用子级页面 document. ...
- 查询sql 索引
SELECT indexname = a.name , tablename = c. name , indexcolumns = d .name , a .indidFROM sysindexes a ...
- RandomAccessFile出现中文乱码问题
之前程序里调用了RandomAccessFile的writeByte(String str)方法,报文里存在中文的时候出现了乱码 后面换成了 write(byte b[])或writeBytes(by ...
- 2018-2019 20165221 网络对抗 Exp5 MSF基础
2018-2019 20165221 网络对抗 Exp5 MSF基础 实践内容: 重点掌握metassploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 一个主动攻击实践,如ms0 ...
- HDU - 1062
格式错误2遍:没考虑到连续两个空格的情况,遇到空格最后要输出这个空格,因为题目只需要转换单词. 另外,开cin,cout加速要注意读入不能用scanf,printf,puts,getchar这些.ge ...
- 论文笔记:Image Smoothing via L0 Gradient Minimization
今天要分享的这篇论文是我个人最喜欢的论文之一,它的思想简单.巧妙,而且效果还相当不错.这篇论文借助数学上的 \(L_0\) 范数工具对图像进行平滑,同时保留重要的边缘特征,可以实现类似水彩画的效果(见 ...
- 3D Slicer中文教程(五)—三维视图颜色改变
3D Slicer在分割后三维重建的图像,效果很好,但是存在一定的不足,默认的颜色并不是很合适,这时手动设置三维视图下的需要的颜色就很有必要了.如下图所示,默认的三维重建后的颜色. 这样的颜色显然不是 ...
- [NOIP2017提高组]小凯的疑惑-扩展欧几里得
#include<bits/stdc++.h> using namespace std; long long a,b,x,y,ans,tmp; inline void ex_gcd(lon ...
- C++ opentracing zipkin
Useful page : https://github.com/openzipkin/b3-propagation & other official websites Steps to ru ...