题面

传送门
Cow Contest
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 24342 Accepted: 13539
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

题目大意

能知道哪些牛比哪些牛强,问可以确定排名的牛有多少。

解题思路

能确定排名,那么这头牛与其他牛的关系得是确定的,就利用形似floyd算法的方式找传递闭包。

AC代码

#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;const int maxn = 101;
bool f[maxn][maxn];
int n, m, ans = 0;void floyd(void){for(int k = 1; k <=n ; k++)for(int i = 1; i <=n ; i++)for(int j = 1; j <= n; j++)f[i][j]=(f[i][k]&&f[k][j]) ? 1 : f[i][j];
}int main(){memset(f,0,sizeof(f));scanf("%d%d", &n,&m);for(int i = 1, u, v; i <= m; i++){scanf("%d%d",&u,&v);f[u][v]=1;}floyd();for(int i = 1,cnt;  i <= n; i++){cnt = 0;for(int j = 1; j <= n; j++){cnt+=f[i][j]||f[j][i];}if(cnt == n-1)ans++;}printf("%d\n",ans);// system("pause");return 0;
}

[传递闭包]POJ#3660 Cow Contest相关推荐

  1. POJ 3660 Cow Contest [Floyd]

    POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...

  2. POJ 3660 Cow Contest 传递闭包+Floyd

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

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

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

  4. POJ 3660 Cow Contest (闭包传递)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7690   Accepted: 4288 Descr ...

  5. poj 3660 Cow Contest 传递闭包

    题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...

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

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

  7. POJ 3660 Cow Contest

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

  8. POJ - 3660 Cow Contest(最短路变形+闭包传递)

    题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...

  9. POJ - 3660 Cow Contest(flod)

    题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的. 分析: 1.a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所 ...

最新文章

  1. Ciruy英雄谭 Chapter 3 杂谈
  2. 介绍Python中方法ljust(),rjust(),center()和zfill()
  3. Java的不同版本:J2SE、J2EE、J2ME的区别
  4. java代码示例(6-3)
  5. EShop网上商城项目(二)
  6. JAVA菜鸟教程(一)
  7. aboutface4 1-3 读书笔记 幕布 思维导图
  8. python自动登录qq邮箱_python和selenium实现163邮箱自动登陆
  9. 双系统基础上装三系统教程
  10. android自定义彩虹,Android彩虹菜单
  11. 【深度学习】常见优化算法
  12. 软件工程学习(十)常见的软件架构
  13. 如何在连不上wifi的情况下连上wifi
  14. 海瑞单薄 台词深奥 《大明王朝》续集全面“纠错”
  15. PostgreSQL 按指定顺序排序
  16. C#筛选DataTable的数据
  17. Android blueZ HCI(二):hcitool hcidump常用方法
  18. 报表服务器导出报表文件名乱码,excel 导出文件名乱码
  19. 计算机专业英语读写比赛,四年级英语读写大赛lpar;初赛rpar;
  20. MySQL 案例实战--MySQL 数据库 之 冷备份

热门文章

  1. Unity 星球旋转效果
  2. linux生成私钥 prk,自动生成RSA密钥,并进行加密和解密1
  3. JS 判断是否为对象的方法
  4. 央行数字货币突然“赛马”试点!但其走过的“长征路”却鲜为人知
  5. OneNote2016 找不到贴纸和emoji 按win键加点键没有效果
  6. 金融行业营改增:从战略到战术的攻坚战
  7. 字节提前批——抖音开放平台一面
  8. Word文件限制编辑怎么办?
  9. 麦肯锡意识-艾森·拉塞尔、保罗·弗里嘉
  10. windows和android平板,说一说安卓,苹果,和Windows平板的差别,看到好多人纠结