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 ...
随机推荐
- Hadoop集群管理
1.简介 Hadoop是大数据通用处理平台,提供了分布式文件存储以及分布式离线并行计算,由于Hadoop的高拓展性,在使用Hadoop时通常以集群的方式运行,集群中的节点可达上千个,能够处理PB级的数 ...
- [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单
Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...
- 【转】Unity四元数和向量相乘作用及其运算规则
作用:四元数和向量相乘表示这个向量按照这个四元数进行旋转之后得到的新的向量. 比如:向量vector3(0,0,10),绕着Y轴旋转90度,得到新的向量是vector3(10,0,0). 在unity ...
- [转载] win10进行端口转发
1.添加端口转发netsh interface portproxy add v4tov4 listenport=4000 listenaddress=127.0.0.1 connectport=400 ...
- zipline框架--简介
Zipline is a Pythonic algorithmic trading library. It is an event-driven system for backtesting. Zip ...
- Java SE之[静态成员/类成员]与[非静态成员/实例成员]【static】
定义 静态成员:又称类成员,使用static修饰符的方法和变量: 非静态成员:又称实例成员,未使用static修饰符的方法和变量. 结论 注:jdk1.8 测试源码 public class Main ...
- element-ui多选框模糊搜索输入文字闪动问题
.el-select__tags { .el-select__input { width: 50px !important; } } 添加这段代码即可 <el-select v-model=&q ...
- P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
对于一个牛,它存在两种状态:1.处于联通分量 2.不处于联通分量.对于处于联通分量的牛,求出联通分量的大小:对于不处于联通分量的牛,求出其距离联通分量的路程+联通分量大小. 不同的联通分量,染上不同的 ...
- 安装spring tool suite时遇到的问题
首先在Eclipse的市场里没有找到,在官网下载安装包后不能安装,于是找了解决办法,跟安装suite的版本还有关系. 我下的是http://download.springsource.com/rele ...
- Input子系统(二)【转】
转自:http://blog.chinaunix.net/uid-25047042-id-4192368.html 上一篇中粗略的分析了下input_dev,input_handle,input_ha ...