本文共 2881 字,大约阅读时间需要 9 分钟。
1034 Head of a Gang (30 point(s))
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made between the two persons. A "Gang" is a cluster of more than 2 persons who are related to each other with total relation weight being greater than a given threthold K. In each gang, the one with maximum total weight is the head. Now given a list of phone calls, you are supposed to find the gangs and the heads.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive numbers N and K (both less than or equal to 1000), the number of phone calls and the weight threthold, respectively. Then N lines follow, each in the following format:
Name1 Name2 Time
where Name1
and Name2
are the names of people at the two ends of the call, and Time
is the length of the call. A name is a string of three capital letters chosen from A
-Z
. A time length is a positive integer which is no more than 1000 minutes.
Output Specification:
For each test case, first print in a line the total number of gangs. Then for each gang, print in a line the name of the head and the total number of the members. It is guaranteed that the head is unique for each gang. The output must be sorted according to the alphabetical order of the names of the heads.
Sample Input 1:
8 59AAA BBB 10BBB AAA 20AAA CCC 40DDD EEE 5EEE DDD 70FFF GGG 30GGG HHH 20HHH FFF 10
Sample Output 1:
2AAA 3GGG 3
Sample Input 2:
8 70AAA BBB 10BBB AAA 20AAA CCC 40DDD EEE 5EEE DDD 70FFF GGG 30GGG HHH 20HHH FFF 10
Sample Output 2:
0
经验总结:
emmmm 英文实在写的太不爽,而且自己水平有限还词不达意,以后还是用中文啦~ 程序猿何苦为难程序猿嘛~
这一题,首先要注意,人家说的是 N<=1000,所以总共可能的最大人数为2000(所有行的两个人都不一样),其他的,就....还有一点吧,这一题可以使用map<string, struct> 的形式进行并查集搜索,也可以将string 转换成对应的唯一的号码进行常规的并查集搜索,当然,因为STL的速度显然没有数组快,所以后者的速度会更快一些~AC代码
#include#include #include #include #include #include
转载地址:https://meteorrain.blog.csdn.net/article/details/86617494 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!