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 ≤ NA ≠ 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传递闭包)的更多相关文章

  1. POJ3660——Cow Contest(Floyd+传递闭包)

    Cow Contest DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a prog ...

  2. POJ3660 Cow Contest —— Floyd 传递闭包

    题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  3. POJ-3660 Cow Contest Floyd传递闭包的应用

    题目链接:https://cn.vjudge.net/problem/POJ-3660 题意 有n头牛,每头牛都有一定的能力值,能力值高的牛一定可以打败能力值低的牛 现给出几头牛的能力值相对高低 问在 ...

  4. POJ3660 Cow Contest floyd传递闭包

    Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...

  5. POJ-3660.Cow Contest(有向图的传递闭包)

      Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17797   Accepted: 9893 De ...

  6. ACM: POJ 3660 Cow Contest - Floyd算法

    链接 Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Descri ...

  7. POJ 3660 Cow Contest(传递闭包floyed算法)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3234 Descr ...

  8. POJ 3660 Cow Contest【传递闭包】

    解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...

  9. poj 3660 Cow Contest (传递闭包)

    /* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...

随机推荐

  1. 【python模块】——logging

    python学习——logging模块

  2. npm 版本问题

    STF之问题篇 https://yq.aliyun.com/articles/221602 装完成后输入stf doctor查看工具依赖是否正确,安装教程可以参考我之前写的,这里不再多说,直接说问题. ...

  3. BZOJ 1923 SDOI2010 外星千足虫 异或方程组+bitset

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1923 懒得贴题目了......这就是解一个异或方程组的裸题...... YY了一下异或方程 ...

  4. BZOJ 3597 SCOI2014 方伯伯送椰子 网络流分析+SPFA

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3597 Description 四川的方伯伯为了致富,决定引进海南的椰子树.方伯伯的椰子园十 ...

  5. 使用PNotify构建消息弹窗

    参考地址 官网:http://sciactive.com/pnotify/ GitHub:https://github.com/sciactive/pnotify npm仓库:https://www. ...

  6. 剑指offer:从头到尾打印链表

    目录 题目 解题思路 具体代码 题目 题目链接 剑指offer:从头到尾打印链表 题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 解题思路 首先题目实际给出的要求是返回ve ...

  7. python中通过string类名获得实例

    原文:https://bytes.com/topic/python/answers/42866-how-create-object-instance-string Ksenia Marasanova的 ...

  8. eniac世界第二台计算机

    ENIAC,全称为Electronic Numerical Integrator And Computer,即电子数字积分计算机.ENIAC是世界上第一台通用计算机,也是继ABC(阿塔纳索夫-贝瑞计算 ...

  9. postman工具中如何提取接口的返回值

    提取接口返回值   当返回值是返回JSON时 1.let json = JSON.parse(responseBody); // responseBody是包含整个返回内容的字符串 提取某字段的值: ...

  10. 算法(12)Best Time to Buy and Sell Stock II

    题目:最大收益 [1,2,3,9,2,3] 思路:这道题竟然是easy的?! 最终的解法非常简单,只要把单个波峰减去波谷就可以了,比如在上面的例子中[1-2-3-9][2-3]这就是单个波峰波谷!为什 ...