POJ 3660 Cow Contest
Description
N (1≤n≤100) cows, conveniently numbered 1..N, is participating in a programming contest. As we all know, some cows code better than others. Each cow have a certain constant skill rating that is unique among the competitors.
The contest is conducted in several head-to-head rounds and each between. If Cow A has a greater skill level than cow B (1≤a≤n; 1≤b≤n; A≠B), then cow A would always beat Cow B.
Farmer John was trying to rank the cows by skill. Given A list the results of M (1≤m≤4,500) Two-cow rounds, determine the number of cows whose ranks can be precisely de Termined from the results. It is guaranteed that the results of the rounds would not be contradictory.
Input
- Line 1:two space-separated integers:n and M
- Lines 2..m+1:each line contains, space-separated integers that describe the competitors and results (the first integer , A, is the winner) of a 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
5 S
3 2
1 2
2 5
Sample Output
2
The main topic: A group of cattle race, each game two cattle to fight, and to distinguish the outcome, now ask you can determine the number of cattle combat effectiveness rankings. Problem solving idea: Warshall algorithm.
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>using namespace STD;typedef Long LongllConst intN = the;intG[n][n];intN, M, T;voidFloyd () { for(intK =1; K <= N; k++) { for(inti =1; I <= N; i++) { for(intj =1; J <= N; J + +) {G[i][j] = G[i][j] | | (G[i][k] & G[k][j]); } } }}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {memsetG0,sizeof(G));intA, B; for(inti =0; I < m; i++) {scanf("%d%d", &a, &b); G[A][B] =1; } Floyd ();intAns =0; for(inti =1; I <= N; i++) {intCNT =0; for(intj =1; J <= N; J + +) {if(G[i][j]) cnt++;if(G[i][j]) cnt++; }if(cnt = = N-1) ans++; }printf("%d\n", ans); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission can also be reproduced, but to indicate the source oh.
POJ 3660 Cow Contest (Warshall algorithm)