日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客假日团队赛8:K.Cow Contest(最短路(floyd)变形)

發布時間:2024/9/3 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客假日团队赛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
    輸入
    復制
5 54 34 23 21 22 5

輸出
復制

2

說明
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。)來記錄
可以確定名次的人的個數
*/

#include <bits/stdc++.h> using namespace std; const int N = 105; int a[N][N];//i--j的距離 int cnt[N];//到達i號點的個數(除了本身) int b[N];//輔助排序的數組 int mp[N];//可達點個數的次數,每個能確定名次的點可達點數目的唯一性 int main() {int n,m;cin>>n>>m;for(int i = 1; i <= n; i++){cnt[i] = 0;mp[i] = 0;for(int j = 1; j <= n; j++){if(i==j) a[i][j] = 0;else a[i][j] = -100000;}}int x,y;for(int i = 1; i<= m; i++){cin>>x>>y;a[y][x] = 1;}for(int k = 1; k <= n; k++){for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){a[i][j] = max(a[i][j],a[i][k]+a[k][j]);}}}for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){if(a[i][j] > 0) cnt[j]++;}}int k = 0;for(int i = 1; i<= n; i++){b[k++] = cnt[i];mp[cnt[i]]++;}sort(b,b+k);int ans = 0;for(int i = 0; i < k; i++){if(b[i]==i&&mp[b[i]]==1)ans++;}cout<<ans<<endl;return 0; } 與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的牛客假日团队赛8:K.Cow Contest(最短路(floyd)变形)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。