【POJ-3660】解题报告(Floyd传递闭包)
原始题目
Cow Contest
- Time Limit: 1000MS
- Memory Limit: 65536K
- Total Submissions: 15815
- Accepted: 8813
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
Source
USACO 2008 January Silver
题目大意
一共有N头牛,现在知道M条信息,每条信息描述两头牛谁更强一些,问可以确定最多多少头牛的排名。
解题思路
- 还在学习中,使用Floyd算法求闭包,(A胜B,B胜C,则传递A胜C)
- 然后对于每头牛扫一遍是否与其他n-1头牛都有确定的胜负关系,如果有的话答案++。
- 还需要深入学习Floyd算法
解题代码
1 |
|
收获与反思
- 挖坑,加强理解Floyd最短路算法。
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!