POJ 3660
题目大意:有N个人,进行M场比赛,M场比赛只给两个参赛选手,第一个就是赢了的参赛选手,求排名固定的参赛选手
结题思路:如果一个人被赢了m次,赢了别人n次,如果m+n==N-1,那么满足条件,Floyd
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #define MAXVERTEXNUM 110 5 #define INF 1000000 6 using namespace std; 7 8 int Nv, Ne; 9 int D[MAXVERTEXNUM][MAXVERTEXNUM]; 10 11 void Floyd() 12 { 13 for (int k = 1; k <= Nv; ++k) 14 for (int i = 1; i <= Nv; ++i) 15 for (int j = 1; j <= Nv; ++j) 16 if (D[i][j] > D[i][k] + D[k][j]) 17 D[i][j] = D[i][k] + D[k][j]; 18 } 19 20 int main() 21 { 22 cin >> Nv >> Ne; 23 for (int i = 1; i <= Nv; ++i) 24 for (int j = 1; j <= Nv; ++j) 25 { 26 if (i == j) 27 D[i][j] = 0; 28 else 29 D[i][j] = INF; 30 } 31 32 for (int i = 1; i <= Ne; ++i) 33 { 34 int V1, V2; 35 cin >> V1 >> V2; 36 D[V1][V2] = 1; 37 } 38 39 Floyd(); 40 41 int getRes[MAXVERTEXNUM]; 42 memset(getRes, 0, sizeof(getRes)); 43 for (int i = 1; i <= Nv; ++i) 44 { 45 for (int j = 1; j <= Nv; ++j) 46 { 47 if (i != j && D[i][j] != INF) 48 { 49 getRes[j]++; 50 getRes[i]++; 51 } 52 } 53 } 54 55 int res = 0; 56 for (int i = 1; i <= Nv; ++i) 57 if (getRes[i] == Nv - 1) 58 res++; 59 60 cout << res << endl; 61 62 return 0; 63 }
不忘初心,方得始终