POJ 3660 Cow Contest (闭包传递)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7690 | Accepted: 4288 |
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来求两点是否连通。这题里,如果一点的入度加上出度等于N-1,那么就可确定这点的等级,因为除了它自己之外的所有节点要么在它之前要么在它之后,不管它前面的节点后后面的节点怎么排序,都不会影响到它。
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 const int SIZE = 105; 6 int N,M; 7 int IN[SIZE],OUT[SIZE]; 8 bool G[SIZE][SIZE]; 9 10 int main(void) 11 { 12 int from,to; 13 int ans; 14 15 while(scanf("%d%d",&N,&M) != EOF) 16 { 17 fill(&G[0][0],&G[N][N],false); 18 for(int i = 0;i <= N;i ++) 19 IN[i] = OUT[i] = 0; 20 21 for(int i = 0;i < M;i ++) 22 { 23 scanf("%d%d",&from,&to); 24 G[from][to] = true; 25 } 26 27 for(int k = 1;k <= N;k ++) 28 for(int i = 1;i <= N;i ++) 29 for(int j = 1;j <= N;j ++) 30 G[i][j] = G[i][j] || G[i][k] && G[k][j]; 31 for(int i = 1;i <= N;i ++) 32 for(int j = 1;j <= N;j ++) 33 if(G[i][j]) 34 { 35 IN[j] ++; 36 OUT[i] ++; 37 } 38 39 ans = 0; 40 for(int i = 1;i <= N;i ++) 41 if(IN[i] + OUT[i] == N - 1) 42 ans ++; 43 printf("%d\n",ans); 44 } 45 46 return 0; 47 }
转载于:https://www.cnblogs.com/xz816111/p/4514960.html
POJ 3660 Cow Contest (闭包传递)相关推荐
- POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest【传递闭包】
解题思路:给出n头牛,和这n头牛之间的m场比赛结果,问最后能知道多少头牛的排名. 首先考虑排名怎么想,如果知道一头牛打败了a头牛,以及b头牛打赢了这头牛,那么当且仅当a+b+1=n时可以知道排名,即为 ...
- [传递闭包]POJ#3660 Cow Contest
题面 传送门 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24342 Accepted: 13539 ...
- POJ - 3660 Cow Contest(最短路变形+闭包传递)
题目链接:点击查看 题目大意:给定n头牛和m个关系,每个关系表示为两个整数a与b,其意义为a牛能打败b牛,问可以确定排名的牛的数量. 题目分析: 在这里先说一下关系闭包: 关系闭包有三种: 自反闭包( ...
- POJ 3660 Cow Contest
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- poj 3660 Cow Contest 传递闭包
题目链接: http://poj.org/problem?id=3660 题目大意: 有n头牛,每头牛都有一个战斗值,农夫约翰想给这些牛排名次,但是只有m场比赛,约翰想知道有多少头牛的名次是确定的. ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Description N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming con ...
- POJ - 3660 Cow Contest(flod)
题意:有N头牛,M个关系,每个关系A B表示编号为A的牛比编号为B的牛强,问若想将N头牛按能力排名,有多少头牛的名次是确定的. 分析: 1.a[u][v]=1表示牛u比牛v强,flod扫一遍,可以将所 ...
最新文章
- Rhel6.0升级内核到3.0.4
- logback的简单使用
- win7开机动画_优化win7系统 让系统运行更顺畅
- python爬取股票实时价格_【美股量化00篇】Python获取新浪接口美股实时数据
- 線陣相機處理時間計算方法
- 澳网:公茂鑫/张择创历史 中国男网夺大满贯首胜
- 北大OJ(POJ 2795)金银岛
- CentOS7文本模式下配置及安装KVM虚拟机
- (四)Linux 安装 jdk
- HTML是由____构成的____文件,JSP填空题
- CMOS和TTL电路区别
- 山东轻工业学院CSDN高校俱乐部参加“新一代语音云发布暨语音开发者大会”与“2012百度开发者大会”体会心得
- c语言三角函数乘法怎么表示,C语言实现三角函数表
- Machine learning techniques to enable closed-loop control in anesthesia-笔记
- 2021年汽车驾驶员(技师)考试题及汽车驾驶员(技师)找解析
- linux ps查看完整时间,Linux ps 命令查看进程启动及运行时间
- SVN conflict的解决办法
- 电子学:第009课——实验 7:研究继电器
- leetcode中等之1709.访问日期之间最大的空档期
- 简历中写工作经历,应该注意哪些方面?