Sicily 2012. King

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

2
01
00

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值