编程介的小学生 2019-12-30 21:48 采纳率: 20.5%
浏览 67

Trouble with Election! 程序设计的思路

Problem Description
Taman and his friends are going to arrange an election for their club. The rule of this election is simple. Every member of the club can cast a single vote for one person. Even one can vote for himself too. If A casts his vote for B and B casts his vote for C then it means that C gets both the votes of A and B. It means if a man casts his vote for someone then the votes he got will also be added to the person he votes for. Now there is a problem if A’s vote goes for B and B’s vote for A. In this case, both of them have the same number of votes and it is a tie! So a tiebreaker will be needed. In this situation, all the votes of A and B and their supporters will be cancelled. If one’s vote goes for another then one is considered as the supporter of another.
Now you are elected as the election commissioner for the election of the club. It is your duty to publish the result of the election. If you find no possible winner or if two or more members have same number of votes then you should declare the situation as “Trouble”, print the name of the winner otherwise. Instead of name, a unique number for each member identifies the members of this club and the number should always be non-negative and less than the total number of members of the club.

Input
There will be multiple test cases. Every test case starts with a single integer N on a line. 0<N<= 100000. N denotes the number of members of the club. N lines following. Each I’th line will be consisting of a single integer J; denoting I’th member casts his vote for J’th member. 0<=I, J<N.

Output
The output for every case consists of a single integer, which denotes that the M’th member is the winner or a single word, “Trouble”, if a unique winner can not be determined. Here quotes are for clarity.

Sample Input
3
1
2
2
4
1
2
0
3
2
1
0
5
1
2
0
2
3
10
7
6
1
8
9
2
7
9
5
4

Sample Output
2
3
Trouble
Trouble
Trouble

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器