usaco training <1.2 Greedy Gift Givers>
题面
| Task 'gift1': 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 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.
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.
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.
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 characters, '\n' and '\r'. Do not let your program get trapped by this!
PROGRAM NAME: gift1
INPUT FORMAT
| Line # | Contents | |||
|---|---|---|---|---|
| 1 | A single integer, NP | |||
| 2..NP+1 | Line i+1 contains the name of group member i | |||
| NP+2..end | NP groups of lines organized like this:
|
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 0
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 starting 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.
SAMPLE OUTPUT (file gift1.out)
dave 302 laura 66 owen -359 vick 141 amr -150
OUTPUT EXPLANATION
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 |
| Finally, 'vick' gives 0 to no one: | ||||
| dave | laura | owen | vick | amr |
| 302 | 66 | -359 | 141 | -150 |
题意
usaco training <1.2 Greedy Gift Givers>的更多相关文章
- usaco training <1.2 Your Ride Is Here>
题面 Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often ...
- USACO Training Section 1.1 Your Ride Is Here
题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...
- 关于USACO Training
做了这么久的题目,突然发现最经典的 USACO Training 还没有做过?加速水一遍吧!我会把题解放在上面的.
- USACO Training Section 1.1 坏掉的项链Broken Necklace
题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的. 这里是 n=29 的二个例子: 第一和第二个珠子在图片中已经被作记号. 图片 A ...
- USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers
P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...
- USACO Training Section 1.2 双重回文数 Dual Palindrom
题目描述 如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做"回文数".例如,12321就是一个回文数,而77778就不是.当然,回文数的首和尾都应是非零的,因此0220就 ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
- USACO 1.1.1 YOUR RIDE IS HERE
众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走.他们为每 ...
随机推荐
- 2019.10.26 CSP%您赛第三场
\(CSP\)凉心模拟^_^ --题源\(lqx.lhc\)等各位蒟蒻 题目名称 比赛 传递消息 开关灯 源文件名 \(competition.cpp\) \(message.cpp\) \(ligh ...
- Mybaits 源码解析 (二)----- 根据配置文件创建SqlSessionFactory(Configuration的创建过程)
我们使用mybatis操作数据库都是通过SqlSession的API调用,而创建SqlSession是通过SqlSessionFactory.下面我们就看看SqlSessionFactory的创建过程 ...
- 省市区三级联动(vue)
vue项目中使用到三级联动,现在自己实现一个三级联动,仅供大家参考一下,直接上代码. <template> <section class="container"& ...
- Mysql 性能优化及问题
MySQL max_allowed_packet设置及问题 查看 max_allowed_packet show VARIABLES like '%max_allowed_packet%'; 以下内容 ...
- $POJ2942\ Knights\ of\ the\ Round\ Table$ 图论
正解:图论 解题报告: 传送门! 一道,综合性比较强的题(我是萌新刚学$OI$我只是想练下$tarjan$,,,$QAQ$ 考虑先建个补图,然后现在就变成只有相互连边的点不能做邻居.所以如果有$K$个 ...
- MySql数据库优化必须注意的四个细节(方法)
MySQL 数据库性能的优化是 MySQL 数据库发展的必经之路, MySQL 数据库性能的优化也是 MySQL 数据库前进的见证,下文中将从从4个方面给出了 MySQL 数据库性能优化的方法. 1. ...
- 在线API文档管理工具Simple doc
Simple doc是一个简易的文档发布管理工具,为什么要写Simple doc呢?主要原因还是github的wiki并不好用:没有目录结构,文章没有Hx标签索引,最悲剧的是文章编辑的时候不能直接图片 ...
- 学习笔记69_Logistic回归
Logistic回归(逻辑回归)进行分类的主要思想:根据现有数据对分类边界线建立回归公式,以此进行分类. 知乎上的简述: 该算法可根据已知的一系列因变量估计离散数值(比方说二进制数值 0 或 1 ,是 ...
- LVS DR模式实践
client:192.168.4.10/24 proxy:192.168.4.5/24 VIP: 192.168.4.15/24 web1:192.168.4.100/24 VIP:192.168 ...
- [考试反思]1106csp-s模拟测试103: 渺茫
7点之前上不了博客,用gedit写的.谅解一下. 看起来不是特别惨?但是被sdfz爆踩了...而且其实并不能说“不是特别惨”吧90分算个啥啊?还凑不出个T2的AC难易度评估错误,T2是最简单的没看出来 ...