题目信息

题目类型
练习
题目年份
2025
题目题型
编程题
关 键 词
贪婪的礼物送礼者

题目题干

贪婪的礼物送礼者

对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。给出一群朋友, 没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表,请确定每个人收到的比送出的钱多的数目。ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

输入

测试系统是 Linux 符合标准的 Unix 的协定。用'\n'作为行的结束。这和 Windows 系统用'\n' 和 '\r'作为行的结束是不同的。你的程序不要被这困住了。 第 1 行: 人数NP,2<= NP<=10ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库
第 2到 NP+1 行: 这NP个在组里人的名字 一个名字一行 第NP+2到最后: 这里的NP段内容是这样组织的: 第一行是将会送出礼物人的名字。 第二行包含二个数字: 第一个是原有的钱的数目(在0到2000的范围里),第二个NGi是将收到这个送礼者礼物的人的个数 如果 NGi 是非零的, 在下面 NGi 行列出礼物的接受者的名字,一个名字一行。ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

输出

输出 NP 行 每行是一个的名字加上空格再加上收到的比送出的钱多的数目。 对于每一个人,他名字的打印顺序应和他在输入的2到NP+1行中输入的顺序相同。所有的送礼的钱都是整数。 每个人把相同数目的钱给每位要送礼的朋友,而且尽可能多给,不能给出的钱被送礼者自己保留。ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

样例

输入

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

输出

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

提示

Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to any or all of the other friends. Likewise, each friend might or might not receive money from any or all of the other friends. Your goal in this problem is to deduce how much more money each person gives than they receive. The rules for gift-giving are potentially different than you might expect. Each person sets aside 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 3 among 2 friends would be 1 each for the friends with 1 left over -- that 1 left over stays in the giver's "account". 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 more (or less) each person in the group gives than they receive.ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

IMPORTANT NOTE The grader machine is a Linux machine that uses standard Unix conventions: end of line is a single character often known as '\n'. This differs from Windows, which ends lines with two charcters, '\n' and '\r'. Do not let your program get trapped by this!ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

PROGRAM NAME: gift1ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

INPUT FORMAT Line 1: The single integer, NPftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库
Lines 2..NP+1: Each line contains the name of a group member Lines NP+2..end: NP groups of lines organized like this: The first line in the group tells the person's name who will be giving gifts.ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库
The second line in the group contains two numbers: The initial amount of money (in the range 0..2000) to be divided up into gifts by the giver and then the number of people to whom the giver will give gifts, NGi (0 ≤ NGi ≤ NP-1).ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库
If NGi is nonzero, each of the next NGi lines lists the the name of a recipient of a gift.ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

SAMPLE INPUT (file gift1.in) 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 0ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

OUTPUT FORMAT 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 on line 2 of the input. 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.ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

SAMPLE OUTPUT (file gift1.out) dave 302 laura 66 owen -359 vick 141 amr -150ftb100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库

答案解析

相关题目

13号星期五 13号又是星期五是一个不寻常的日子吗?13号在星期五比在其他日少吗?为了回答这个问题,写一个程序来计算在n年里13日落在星期一,星期二......星期日的次数.这个测试从1900年1月1
贪婪的礼物送礼者 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,
你要乘坐的飞碟在这里 一个众所周知的事实,在每一慧星后面是一个不明飞行物UFO。 这些不明飞行物时常来收集来自在地球上忠诚的支持者。 不幸地,他们的空间在每次旅行只能带上一群支持者。 他们要做的是用一
删除数组中的元素 题目描述 给定N个整数,将这些整数中与M相等的删除 假定给出的整数序列为:1,3,3,0,-3,5,6,8,3,10,22,-1,3,5,11,20,100,3,9,3 应该将其放在
统计学生信息 ​​​​​​​题目描述 利用动态链表记录从标准输入输入的学生信息(学号、姓名、性别、年龄、得分、地址) 其中,学号长度不超过20, 姓名长度不超过40, 性别长度为1, 地址长度不超过
等待服务 题目描述 n个人的队伍,其中第i个人需要t[i]分钟来服务,期间后面的人就要等着。如果一个人等待的时间大于了他被服务的时间,他就会失望。你的任务是重排队伍,使失望的人尽量的少,并只需输出不
CPU任务 题目描述 CPU通过循环调度法逐一处理任务,每个任务最多处理q毫秒(这个时间称为时间片)。如果q毫秒之后任务尚未处理完毕,那么该任务将被移动至队伍最末尾,CPU随即开始处理下一个任务。
瓶子和燃料 题目描述 jyy就一直想着尽快回地球,可惜他飞船的燃料不够了。 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换。jyy 的飞船上共有 N个瓶子(1<=N&
切比雪夫距离 题目描述 小C有一个平面! 它发现了平面上的两个点,请你求出求它们之间的切比雪夫距离。切比雪夫距离定义为x与y方向坐标差的绝对值较大值。 输入 四个整数,a,b,c,d。坐标为(a
横式竖式计算 题目描述 输入两个数,分别打印这两个数的横式和竖式运算式子。 输入 输入两个整数a,b 以空格隔开 输出 第一行打印横式运算式子,接下来四行打印竖式运算式子 样例输入  45 23

提示声明

  • 免责声明:本站资源均来自网络或者用户投稿,仅供用于学习和交流:如有侵权联系删除!
  • 温馨提示:本文属于积分文章,需要充值获得积分或升级VIP会员,也可在会员中心投稿获取。

猜你喜欢