
本文共 3393 字,大约阅读时间需要 11 分钟。
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 threshold 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
题意:
警察找到团伙头的一种方法是检查人们的电话。如果A和B之间有电话,我们说A和B是相关的。关系的权重定义为两个人之间进行的所有电话呼叫的总时间长度。 “帮派”是由两个以上彼此相关的人员组成的集群,总关系权重大于给定的阈值K。在每个帮派中,总权重最大的是头。现在给出电话列表,您应该找到帮派和团长。
输入规格:
每个输入文件包含一个测试用例。对于每种情况,第一行都包含两个正数N和K(均小于或等于1000),电话数量和权重阈值。然后N行,每行采用以下格式:
名称1 名称2 时间
其中Name1和Name2是通话两端的人员名称,Time是通话时间。名称是从A-Z中选择的三个大写字母的字符串。时间长度是一个不超过1000分钟的正整数。
输出规格:
对于每个测试用例,首先在一行中打印帮派总数。然后,对于每个团伙,在一行中打印头的名称和成员总数。可以确保每个帮派头都是唯一的。必须根据标题名称的字母顺序对输出进行排序。
样本输入1:
8 59AAA BBB 10BBB AAA 20AAA CCC 40DDD EEE 5EEE DDD 70FFF GGG 30GGG HHH 20HHH FFF 10
样本输出1:
2AAA 3GGG 3
样本输入2:
8 70AAA BBB 10BBB AAA 20AAA CCC 40DDD EEE 5EEE DDD 70FFF GGG 30GGG HHH 20HHH FFF 10
样本输出2:
0
代码:
#include#include #include #include #include #include #include #include #include #include
发表评论
最新留言
关于作者
