2023秋-A-3 Popularity of Education Supermarket Categories
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
In PTA, there is the Education Supermarket which collects all kinds of exam/test problem sets. The sets can be found in several categories.
The popularity of a category is defined to be , where and are the number of users who have opened a set and the total payment received in category , respectively; is the total number of users who have opened a set and is the total payment received in the supermarket.
Your job is to calculate the popularity of any given category.
输入格式
Each input file contains one test case.
For each case, the first line contains a positive integer (), which is the total number of problem sets and the categories.
Then lines follow, each describes a set or category in the following format:
ID1 ID2 type n p
where ID1
is the index of this set or category, which is a 3-digit number; ID2
is the index of the category that contains ID1
-- a category may have several sub-categories or contains several problem sets, and each set/category may only belong to one supper category; type
being 1 means that ID1
is a category, or 0 means it is a problem set; if ID1
is a set, then n
is the number of users who have opened it, and p
is the total payment received for this set (both are non-negative integers no more than ); or if ID1
is a category, there will be no n
or p
following type
.
Note: the supermarket itself is the only root category, and its corresponding ID2
will be given as .
Finally, another positive integer () is given, and is followed by category ID
's in the next line.
输出格式
For each query of category, we should print in a line its popularity. However, to avoid the lose of accuracy during float number calculations, let's output , , and instead. It is guaranteed that none of or is zero. Note: all the numbers in a line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.
样例
13
001 -1 1
002 001 1
006 002 0 23 45
007 002 0 108 256
005 002 1
003 001 1
011 003 0 0 0
012 003 0 1 5
004 001 1
013 004 0 200 200
008 005 0 35 78
009 005 0 8 26
010 005 0 1130 1516
5
001 002 003 004 005
1505 1505 2126 2126
1304 1505 1921 2126
1 1505 5 2126
200 1505 200 2126
1173 1505 1620 2126
限制
代码长度限制 16 KB Java (javac) 时间限制 700 ms 内存限制 512 MB
其他编译器 时间限制 400 ms 内存限制 64 MB