Sicily 2012. King

来源:互联网 发布:蜂窝移动数据是什么 编辑:程序博客网 时间:2024/05/22 11:58

2012. King

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB , Special Judge

Description

 There are n children in a country marked by integers from 1 to n.

They often fight with each other. For each 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 is not afraid of child B if A can beat B.
Child A is not afraid of child B if A can beat C and C can beat B either. Because A can say "I will call C to beat you" to B.
A child is called a king of children if he is not afraid of any other child.
Give you the beating relations.Find a king.

Input

 The first line contains a 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 will be '1' if and only if A can beat B. Input is 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 are multiple kings, any one is accepted.

Sample Input

20100

Sample Output

1

Problem Source

每周一赛:2010中山大学新手赛

#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;}


0 0