King Constraints
Time limit:1 secs, Memory limit:256 MB, Special Judge
Description
There is n children in a country marked by integers from 1 to n.
They often fight with each other. For the pair of child A and child B, either a beats B or B beats a. It is not possible that both a beats B and B beats a. Of course, one never fight with himself. Child A isn't afraid of child b if a can beat B.child A was not afraid of the child B if a can beat C and C can beat B either. Because A can say "I'll call C-beat you" to B.A child is called A King of children if he's not afraid of any other Child. Give you the beating relations. Find a king.
Input
The first line contains an integer n which is between 1 and 1000. The following n lines contains n characters respectively. Character is either ' 0 ' or ' 1 '. The Bth character of (a+1) th line would be ' 1 ' if and only if A can beat B. Input was terminated by EOF.
Output
A number representing a king of children on a line. If such a king does not exist, output-1. If There is multiple kings, any one is accepted.
Sample Input
20100
Sample Output
1
Problem Source
Every Monday: 2010 Sun Yat-sen University Beginner's tournament
#include <stdio.h>int main () { int n, I, J, Temp_num, King, Max; Char temp[1000]; while (~SCANF ("%d\n", &n)) {for (i = 0, max = 0, king = 0; i < n; i++) { gets (temp); for (j = 0, temp_num = 0; J < N; j + +) { if (temp[j] = = ' 1 ') temp_num++; } if (Temp_num > Max) { max = Temp_num; King = i; } } printf ("%d\n", King + 1); } return 0;}
Sicily 2012. King