牛客假日团队赛8:K.Cow Contest(最短路(floyd)变形)
鏈接:https://ac.nowcoder.com/acm/contest/1069/K
來源:牛客網
時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 32768K,其他語言65536K
64bit IO Format: %lld
題目描述
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.
輸入描述:
- 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
輸出描述: - Line 1: A single integer representing the number of cows whose ranks can be determined
示例1
輸入
復制
輸出
復制
說明
Cow 2 loses to cows 1, 3, and 4. Thus, cow 2 is no better than any of the cows 1, 3, and 4. Cow 5 loses to cow 2, so cow 2 is better than cow 5. Thus, cow 2 must be fourth, and cow 5 must be fifth. The ranks of the other cows cannot be determ
/*
題意大概是:
給出兩個人的比賽成績優劣,
求最終有多少人的名次(排名)可以確定。
構造圖:
通過構造成績低的指向成績高的單向邊來建圖
我們發現,只要確定每個點有多少個其他的點可達
就可以確定哪些點的名次是可以確定的。
為什么呢?
我們知道根據我們建的圖,
名次越低越少的點可達它,
假設有n個點且所有的點名次都確定,
根據名次由低到高,能到達每個點的個數(除了它本身)一定是唯一確定的:
0,1, 2, 3,4,。。n-1。
所以我們可以根據Floyd求出任意兩點的距離,
根據距離判斷每個點有多少個可達點。
然后我們對每個點可達點個數排一個序,
根據類似上面舉例的序列(0,1, 2, 3,4,。。n-1。)來記錄
可以確定名次的人的個數
*/
總結
以上是生活随笔為你收集整理的牛客假日团队赛8:K.Cow Contest(最短路(floyd)变形)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019年湘潭大学程序设计竞赛(重现赛)
- 下一篇: 牛客假日团队赛8:H.Cell Phon