澳门皇冠金沙网站▎在线官网
做最好的网站

1034. Head of a Gang (30)[离散化+并查集+搜索]——PA

2019-11-14 作者:网络服务   |   浏览(163)

1049. Counting Ones (30)[计算1 的个数]——PAT (Advanced Level) Practise

1034. Head of a Gang (30)[离散化+并查集+搜索]——PAT (Advanced Level) Practise

题目信息

  1. Counting Ones (30)

时间限制10 ms
内存限制65536 kB
代码长度限制16000 B

The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12.

Input Specification:

Each input file contains one test case which gives the positive N (<=2^30).

Output Specification:

澳门皇冠金沙网站,在线官网,For each test case, print the number of 1’s in one line.

Sample Input:
12
Sample Output:
5

题目信息

  1. Head of a Gang (30)

时间限制100 ms
内存限制65536 kB
代码长度限制16000 B

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 59
AAA BBB 10
BBB AAA 20
AAA CCC 40
DDD EEE 5
EEE DDD 70
FFF GGG 30
GGG HHH 20
HHH FFF 10
Sample Output 1:
2
AAA 3
GGG 3
Sample Input 2:
8 70
AAA BBB 10
BBB AAA 20
AAA CCC 40
DDD EEE 5
EEE DDD 70
FFF GGG 30
GGG HHH 20
HHH FFF 10
Sample Output 2:
0

本文由澳门皇冠金沙网站发布于网络服务,转载请注明出处:1034. Head of a Gang (30)[离散化+并查集+搜索]——PA

关键词: