POJ3660:Cow Contest(Floyd传递闭包)
Cow Contest
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 16941 | Accepted: 9447 |
题目链接:http://poj.org/problem?id=3660
Description:
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场比赛,然后给出m场比赛的胜负关系,问有多少只牛能确定它们自己的名次。
题解:
这个题有点像拓扑排序,但是只用拓扑序并不能保证结果的正确性。
其实解这个题我们只需要发现这样一个关系就好了,若一只牛的名次能够被确定,那么它赢它的牛和它赢的牛个数之和为n-1。
利用这个关系,我们floyd传递闭包预处理一下,然后判断一下数量关系就好了。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int N = , M = ;
int n,m;
int mp[N][N];
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=;
}
for(int k=;k<=n;k++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
mp[i][j]=(mp[i][j]|(mp[i][k]&mp[k][j]));
}
}
}
int ans=;
for(int i=;i<=n;i++){
int win=,lose=;
for(int j=;j<=n;j++){
if(mp[i][j]) win++;
if(mp[j][i]) lose++;
}
if(win+lose==n-) ans++;
}
cout<<ans;
return ;
}
POJ3660:Cow Contest(Floyd传递闭包)的更多相关文章
- POJ3660——Cow Contest(Floyd+传递闭包)
Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...
- POJ3660 Cow Contest —— Floyd 传递闭包
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ-3660 Cow Contest Floyd传递闭包的应用
题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...
- POJ3660 Cow Contest floyd传递闭包
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17797 Accepted: 9893 De ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
随机推荐
- MongoDB修改数据库名,collection名
利用dropDatabase,copyDatabase修改Database名称 db.copyDatabase('old_name', 'new_name'); use old_name db.dro ...
- Python学习手册之函数和模块
在上一篇文章中,我们介绍了 Python 的控制结构,现在我们介绍 Python 函数和模块. 查看上一篇文章请点击:https://www.cnblogs.com/dustman/p/9976234 ...
- go学习笔记-函数
函数 定义 格式 func function_name( [parameter list] ) [return_types] { 函数体 } 解析 func:函数由 func 开始声明 functio ...
- R语言学习笔记(八):零碎知识点(16-20)
16--complete.cases( ) complete.case()可以判断对象中是否数据完全,然后返回TRUE, FALSE 这一函数在去除数据框中缺失值时很有用. > d kids a ...
- SQL 公用表表达式(CTE)
1.概念 公用表表达式(Common Table Expression)是SQL SERVER 2005版本之后引入的一个特性.CTE可以看作是一个临时的结果集,可以在接下来的一个SELECT,INS ...
- linux进程 生产者消费者
#include<stdio.h> #include<unistd.h> #include<stdlib.h> #include<string.h> # ...
- 2426: [HAOI2010]工厂选址
2426: [HAOI2010]工厂选址 链接 代码: /* 贪心: 奇妙!!!!! 因为所有的煤矿不是给新厂,就是给旧厂(而且旧厂的得到b) 为了使费用最小,感性的理解,那么一个煤矿给哪个厂,取决于 ...
- unity3d NavMeshAgent 寻路画线/画路径
今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...
- 「日常训练」 Mike and Frog (CFR305D2C)
题意与分析 (Codeforces 548C) 我开始以为是一条数学题,死活不知道怎么做,无奈看题解,才知这是一条暴力,思维江化了- - 题意大概是这样的: 两个东西的初始高度分别为h1,h2&quo ...
- Ubuntu 首次给root用户设置密码
用过ubuntu的人都知道,刚安装好root用户是没有密码的,没有密码我们就没法用root用户登录.给root用户设置密码输入命令sudo passwd root,然后系统会让你输入密码,这时输入的密 ...