Sicily 2012. King

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.