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, '\r\ and ‘\n’. 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: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 giverNGi (0 ≤ NGi ≤ NP), the number of people to whom the giver will give giftsIf NGi 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.

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
/*
ID:
TASK: gift1
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <fstream>
using namespace std;string s[100010];
map <string, int> money;int main()
{ofstream fout("gift1.out");ifstream fin("gift1.in");int N;fin >> N;for(int i = 1; i <= N; i ++){fin >> s[i];}for(int i = 1; i <= N; i ++){string a;fin >> a;int n, m;fin >> n >> m;money[a] -= n;int f = n;for(int j = 1; j <= m; j ++){string t;fin >> t;int g = n / m;f -= g;money[t] += g;}money[a] += f;}for(int i = 1; i <= N; i ++){fout << s[i] << ' ' << money[s[i]] << endl;}return 0;
}

usacoTask ‘gift1’: Greedy Gift Givers相关推荐

  1. Greedy Gift Givers

    原题地址 Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange g ...

  2. USACO题解——Section 1.2——Greedy Gift Givers

    题目地址:https://train.usaco.org/usacoprob2?a=BGOMbIJsisd&S=gift1. 或者我的OJ网站,http://47.110.135.197/pr ...

  3. USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers

    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...

  4. 贪婪的送礼者Greedy Gift Givers [USACO 1.2]

    贪婪的送礼者Greedy Gift Givers [USACO 1.2]题目描述: 有一群(N个)要互送礼物的朋友,现在要确定每个人送出的钱比收到的钱多多少.每个人都准备了一些钱来送礼物,而这些钱将会 ...

  5. USACO Section 1.2 Greedy Gift Givers (简单查找)

    2018-3-25 changed 题目大意就是说我们要互相 " 送钱 " ,一共NP个人,指定某一个人将sum这么多的钱分给num个人,那么这些人每个人多了sum/num,送钱的 ...

  6. USACO1.1.2 - Greedy Gift Givers

    贪婪礼品送货员 一组NP(2≤NP≤10)唯一命名的朋友决定交换礼物的钱.这些朋友中的每一个可能或可能不会给任何或所有其他朋友一些钱.同样,每个朋友可能或可能不从任何或所有其他朋友接收钱.你在这个问题 ...

  7. [USACO1.1]贪婪的送礼者Greedy Gift Givers

    题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人.然而,在任何一群朋友中 ...

  8. YTU ---1402-Greedy Gift Givers 贪婪的送礼者

    1402: 1.1.2 Greedy Gift Givers 贪婪的送礼者 Time Limit: 1 Sec   Memory Limit: 64 MB Submit: 31   Solved: 1 ...

  9. Greedy Gift Takers

    Farmer John's nemesis, Farmer Nhoj, has N cows (1≤N≤105 ), conveniently numbered 1...N .They have un ...

  10. USACO 1.0_Greedy Gift Givers

    2019独角兽企业重金招聘Python工程师标准>>> /* ID: zfb2 LANG: C++ TASK: gift1 */ #include <iostream> ...

最新文章

  1. 关于MySql链接url参数的设置 专题
  2. 1001. [BJOI2006]狼抓兔子【最小割】
  3. 原子性 atomic 类用法
  4. 【论文写作】JSP在线考试系统如何写功能描述
  5. 019-Spring Boot 日志
  6. java docx4j api,docx4j api中文
  7. Origin正版申请
  8. Java____利用HSSF导出、导入excel文件
  9. [字节跳动]2018秋招算法题【持续更新中】
  10. 联想台式计算机光驱启动,联想电脑怎么设置光驱启动【图文】
  11. MySQL 的主从复制(高级篇)
  12. 因为在此系统上禁止运行脚本_按键精灵调试脚本常见问题
  13. 从CVPR 2021的论文看计算机视觉的现状
  14. MPLAB常见问题及解决方法
  15. 关于babe-loader^8.0.6的配置问题
  16. 【人脸识别】解析MS-Celeb-1M人脸数据集及FaceImageCroppedWithAlignment.tsv文件提取
  17. 计算机房配备空调,计算机房使用机房专用空调机的必要性
  18. 【工具篇-LaTeX】LaTeX语法
  19. Threejs—sketch 素描特效实现
  20. 魔兽争霸3地图(WarIII Maps):终焉之战

热门文章

  1. 自己写的一个SP工具类
  2. 机器学习 - 聚类 DBSCAN算法(基于密度的空间聚类算法) (学习笔记)
  3. activity的好处
  4. 数据结构Set和Map
  5. pip安装python库速度慢、失败及超时报错解决办法
  6. 恢复视力的方法(飞行员都用) 为了你的眼睛请收藏吧 - Qzone日志
  7. SSM中关于日期的处理
  8. VS2017中对于上传文件时出现没有权限出错解决方法
  9. 2021-08-16 Windows 清除Samba的共享文件夹链接
  10. 沪深300股指期权如何交易的呢?