/ 7FOJ / 题库 /

Greedy Gift Givers 贪心的送礼者

Greedy Gift Givers 贪心的送礼者

背景

  • Idea: USACO
  • Data: USACO
  • Solution: USACO
  • 题面: USACO
  • Translate: oistream

本题来自 USACO 1.2 Greedy Gift Givers

描述

A group of \(NP~(2 \leq NP \leq 10)\) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to some or all of the other friends (although some might be cheap and give to no one). Likewise, each friend might or might not receive money from any or all of the other friends. Your goal is to deduce how much more money each person receives than they give.

有 \(NP\) 个名字不同的朋友决定互相送钱作礼物。每个人会(也可能不会)给一些(或除自己外的所有)人一些钱(虽然其中有一些可能数额很低或不发给任何人)。同样的,每一个人会(也可能不会)从一些(或除自己外的所有)人那里收到钱。你需要推断出每个人最终的钱数。

The rules for gift-giving are potentially different than you might expect. Each person goes to the bank (or any other source of money) to get a certain amount of money to give and divides this money evenly among all those to whom he or she is giving a gift. No fractional money is available, so dividing \(7\) among \(2\) friends would be \(3\) each for the friends with \(1\) left over – that \(1\) left over goes into the giver's "account". All the participants' gift accounts start at \(0\) and are decreased by money given and increased by money received.

送钱的规则和你预测的可能不同。每个人从银行(或其他可以获得钱的途径)取出一定数额的要送的钱,并将这些钱均匀分给所有他/她要送给钱的人。分数数额的钱是不合法的,所以将数额为 \(7\) 的钱分给 \(2\) 个人,这 \(2\) 个人会各得到数额为 \(3\) 的钱,并余数额为 \(1\) 的钱下来,余下的数额为 \(1\) 的钱留在发钱的人的手中。最初所有人拥有的钱的数额均为 \(0\),每个人拥有的钱的数额会随着他/她收到钱而增加,或随着他/她送出钱而减小。

In any group of friends, some people are more giving than others (or at least may have more acquaintances) and some people have more money than others.

在每组朋友中,一些人会比其他人给出更多的钱(或者至少有更多的熟人),一些人(最终)拥有的钱的数额会多余其他人。

Given:

给定以下数据。

  • a group of friends, no one of whom has a name longer than \(14\) characters,
  • 一组朋友(的名字)。
  • the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts,
  • 每个人要给出的钱,和一个包含了这个人要将钱给的人的列表。

determine how much money each person ends up with.

求出每个人最终会有多少钱。

输入格式

Line # Contents
\(1\) A single integer, \(NP\)
\(2\sim NP+1\) Line \(i+1\) contains the name of group member \(i\)
\(NP+2\sim \text{end}\) \(NP\) groups of lines organized like this: The first line of each group tells the person's name who will be giving gifts. The second line in the group contains two numbers: The amount of money (in the range \([0,2000]\)) to be divided into gifts by the giver \(NG_i~(0 \leq NG_i \leq NP)\), the number of people to whom the giver will give gifts. If \(NG_i\) is nonzero, each of the next NGi lines lists the name of a recipient of a gift; recipients are not repeated in a single giver's list.
行号 给出的信息
\(1\) 一个整数,\(NP\)
\(2\sim NP+1\) 第 \(i+1\) 行包含第 \(i\) 组朋友的名字
\(NP+2\sim end\) \(NP\) 组数据,按如下格式输入:每一组的第一行给出要给钱的人名。第二行包含两个整数,要给出的钱数和将收到礼物的人的个数 \(NG_i\)。如果 \(NG_i\) 非零,则接下来的 \(NG_i\) 行每行包含一个即将收到礼物的人的姓名(并且在同一个送礼者的列表里不会重复出现同一个收钱者)。

输出格式

The output is \(NP\) lines, each with the name of a person followed by a single blank followed by the net gain or loss (final_money_value - initial_money_value) for that person. The names should be printed in the same order they appear starting on line 2 of the input.

输出有 \(NP\) 行,每行包含:一个人的姓名,用空格分隔后输出该人收到的钱比给出的钱多的数额。输出的姓名顺序必须与输入中的姓名顺序相同。

All gifts are integers. Each person gives the same integer amount of money to each friend to whom any money is given, and gives as much as possible that meets this constraint. Any money not given is kept by the giver.

每个人给出的钱必须是整数,并且每个收钱者应收到尽可能多的整数数额的钱。剩下的钱回到送礼者的手中。

样例

输入样例1

5
dave
laura
owen
vick
amr
dave
200 3
laura
owen
vick
owen
500 1
dave
amr
150 2
vick
owen
laura
0 2
amr
vick
vick
0 0

输出样例1

dave 302
laura 66
owen -359
vick 141
amr -150

样例解释

Five names: dave, laura, owen, vick, amr. Let's keep a table of the gives (money) each person 'has':

dave laura owen vick amr
0 0 0 0 0

First, 'dave' splits 200 among 'laura', 'owen', and 'vick'. That comes to 66 each, with 2 left over

-200+2 +66 +66 +66 0
-198 66 66 66 0

Second, 'owen' gives 500 to 'dave':

-198 +500 66 66 -500 66 0
302 66 -434 66 0

Third, 'amr' splits 150 between 'vick' and 'owen':

302 66 -434 +75 66 +75 -150
302 66 -359 141 -150

Fourth, 'laura' splits 0 between 'amr' and 'vick'; no changes:

302 66 -359 141 -150
302 66 -359 141 -150

Finally, 'vick' gives 0 to no one:

dave laura owen vick amr
302 66 -359 141 -150

数据规模与约定

对于全部数据,\(2\leq NP\leq 10\),人名长度不超过 \(14\) 个字符,送钱的数额在 \([0,2000]\) 范围内,对于所有的 \(i\),均有 \(0\leq NG_i\leq NP\)。

信息

ID
1105
难度
2
分类
模拟 点击显示
标签
递交数
1
已通过
1
通过率
100%
被复制
1
上传者

相关

在下列训练计划中:

USACO 题目合集