Summary ..
1. Use Topology Sorting to determine the ranking of the competition using toposort () use ans [] to record the entry point to zero and then output it in sequence (this is not a ring by default); pay attention to the handling of the inbound level at any time ;; (such as hdu1285 ))
, 2. When using to generate a champion: record the level of entry. Finally, there are several points with zero level of entry. If there are multiple points, there will be no champions. Otherwise, vice versa ;;
3. When determining whether a ranking can be determined (neither ring nor ring), toposort () is used. The difference between toposort () and 1 is that several people have to have a few 0 inbound degrees .. If one is not, it cannot be determined .. This does not need to be saved, and (such as hdu3342) # include <stdio. h>
# Include <string. h>
Int degree [1001], K;
Char name [2, 1001] [20];
Int fun (char * s)
{
Int I;
For (I = 0; I <K; I ++)
If (strcmp (name [I], S) = 0)
Break;
If (I = K)
{
Strcpy (name [K], S );
K ++;
}
Return I;
}
Int main ()
{
Int m, n, I, j, F1, F2, P;
Char S1 [20], S2 [20];
While (scanf ("% d", & M), m)
{
K = 0;
Memset (degree, 0, sizeof (degree ));
For (I = 0; I <m; I ++)
{
Scanf ("% S % s", S1, S2 );
F1 = fun (S1 );
F2 = fun (S2 );
Degree [F2] ++;
}
P = 0;
For (I = 0; I <K; I ++)
If (degree [I] = 0)
P ++;
If (P = 1)
Printf ("Yes \ n ");
Else
Printf ("NO \ n ");
}
Return 0;
}
# Include <stdio. h>
# Include <string. h> int main () {int m, I, J, K, H; char a [1000] [100], B [1000] [100]; ///// record the name of each contestant: int sum [1000], C [1000]; // record whether to win while (scanf ("% d ", & M), m) {memset (sum, 0, sizeof (SUM);/initialize to make sum = 0, the table fails for (I = 0; I <m; I ++) {scanf ("% S % s", a [I], B [I]); sum [I] = 1 ;}for (I = 0; I <m; I ++) for (j = 0; j <m; j ++) // compare whether the existence of B [I] is the same as that of a [I]. If it exists, it is not the winner {If (strcmp (A [I], B [J]). = 0) sum [I] = 0;} k = 0; for (I = 0; I <m; I ++)
// Store the numbers of all the winners in the failure in the C [] array, and then compare {If (sum [I] = 1) {c [k] = I; k ++ ;}} h = 0; for (I = 1; I <K; I ++) if (strcmp (A [C [I], a [C [I-1]) = 0)
// Compare to see if only one person is in the real winner H ++; If (H = k-1) printf ("Yes \ n "); elseprintf ("NO \ n");} return 0 ;}
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2094
Train of Thought 1: Conditions for winning the championship: (1) the winner did not lose once (2) the winner only has one
Train of Thought 2: Observe, you can see that as long as the total number of elements-loser = 1, you can output yes ..
Train of Thought 3: the winner on the left and the loser on the right. If only one winner on the Left does not appear on the right, this is the champion. Otherwise, it will not.