Greedy Gift Givers 

The Problem

This problem involves determining, for a group of gift-giving friends, how much more each person gives than they receive (and vice versa for those that view gift-giving with cynicism).

In this problem each person sets aside some money for gift-giving and divides this money evenly among all those to whom gifts are given.

However, 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, the money each person in the group spends on gifts, and a (sub)list of friends to whom each person gives gifts; you are to write a program that determines how much more (or less) each person in the group gives than they receive.

The Input

The input is a sequence of gift-giving groups. A group consists of several lines:

  • the number of people in the group,
  • a list of the names of each person in the group,
  • a line for each person in the group consisting of the name of the person, the amount of money spent on gifts, the number of people to whom gifts are given, and the names of those to whom gifts are given.

All names are lower-case letters, there are no more than 10 people in a group, and no name is more than 12 characters in length. Money is a non-negative integer less than 2000.

The input consists of one or more groups and is terminated by end-of-file.

The Output

For each group of gift-givers, the name of each person in the group should be printed on a line followed by the net gain (or loss) received (or spent) by the person. Names in a group should be printed in the same order in which they first appear in the input.

The output for each group should be separated from other groups by a blank line. 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. Any money not given is kept and is part of a person's ``net worth'' printed in the output.

Sample Input

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
3
liz steve dave
liz 30 1 steve
steve 55 2 liz dave
dave 0 2 steve liz

Sample Output

dave 302
laura 66
owen -359
vick 141
amr -150 liz -3
steve -24
dave 27
#include<stdio.h>
#include<string.h>
struct man{char s[15];int m;}p[12];
char temp[15];
int main()
{
int n,i,j,k,pay,num,f=0;
while(scanf("%d",&n)!=EOF)
{
if(f)
printf("\n");
f=1;
memset(&p,0,sizeof(p));
for(i=0;i<n;i++)
scanf("%s",p[i].s);
for(i=0;i<n;i++)
{
scanf("%s%d%d",temp,&pay,&num);
for(j=0;j<n;j++)
if(!strcmp(temp,p[j].s))
if(num)
p[j].m-=num*(pay/num);
for(k=0;k<num;k++)
{
scanf("%s",temp);
for(j=0;j<n;j++)
if(!strcmp(temp,p[j].s))
p[j].m+=pay/num;
}
}
for(i=0;i<n;i++)
printf("%s %d\n",p[i].s,p[i].m);
}
return 0;
}

119 - Greedy Gift Givers的更多相关文章

  1. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  2. USACO Section 1.1-2 Greedy Gift Givers

    Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...

  3. Section 1.1 Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts o ...

  4. 1.1.4 PROB Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  5. Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  6. 洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

    贪婪的送礼者Greedy Gift Givers 难度:☆ Code: #include <iostream> #include <cstdio> #include <c ...

  7. usaco training <1.2 Greedy Gift Givers>

    题面 Task 'gift1': Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided t ...

  8. Greedy Gift Givers 贪婪的送礼者 USACO 模拟

    1002: 1.1.2 Greedy Gift Givers 贪婪的送礼者 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...

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

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

随机推荐

  1. java与C#的简单比较

    刚刚看完java视频,做了个简单图: 新知识不多,大多是与以往知识的相互碰撞,一下做了java与C#的简单比较:                         Java C# 主类名与文件名 必须一 ...

  2. 8天玩转并行开发——第三天 plinq的使用

    原文 8天玩转并行开发——第三天 plinq的使用 相信在.net平台下,我们都玩过linq,是的,linq让我们的程序简洁优美,简直玩的是爱不释手,但是传统的linq只是串行代码,在并行的 年代如果 ...

  3. Linux 下获取LAN中指定IP的网卡的MAC(物理地址)

    // all.h// 2005/06/20,a.m. wenxy #ifndef _ALL_H#define _ALL_H #include <memory.h>#include < ...

  4. python web with bottle and session (beaker)

    python web with bottle and session (beaker) http://icodesnip.com/snippet/python/python-web-with-bott ...

  5. NX-bridge,可以实现无线XBee控制的Arduino板

    ”今天Elecfreaks Studio给你介绍一个新的.很实用的朋友:带有一些奇幻色彩的神秘设备.它是什么呢?它可以完成什么功能呢?它对我们的生活有哪些促进呢?非常感兴趣吧?别着急,我们这就给您详细 ...

  6. JSP的学习(3)——语法知识二之page指令

    本篇接上一篇<JSP的学习(2)——语法知识一>,继续来学习JSP的语法.本文主要从JSP指令中的page指令,对其各个属性进行详细的学习: JSP指令: JSP指令是为JSP引擎而设计的 ...

  7. 把linux可执行程序做成一个服务[转]

    转自:http://www.2cto.com/os/201202/121249.html 在linux系统启动的时候,我们可以看到很多服务性程序一个接一个的被启动(就是那些后面有一个兰色[OK]的行) ...

  8. asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装)

    原文  asp.net中通过注册表来检测是否安装Office(迅雷/QQ是否已安装) 检测Office是否安装以及获取安装 路径 及安装版本  代码如下 复制代码 #region 检测Office是否 ...

  9. 一个与Log4j相关的死锁(转)

    这个死锁的原因:一个动作需要两个临界对象.静态同步方法,就是一个临界对象.这种场景,静态同步方法每次只能有一个线程持有.如果存在另一个临界对象,静态同步方法中也需要获取这个临界对象.即一个动作需要两个 ...

  10. js之checkbox的代码全选/全不选,使用id获取元素,而不是name

    每当有多个选项的时候,都会有一种想法是:全选,全不选,如果子选项有被选,父选项也得被选. 注意:这里是根据id来获取元素的,但是不能直接用getElementById,因为那只能返回一个,而不是集合. ...