Greedy Gift Givers

来源:互联网 发布:淘宝联盟如何推广赚钱 编辑:程序博客网 时间:2024/06/04 20:01

http://train.usaco.org/usacoprob2?a=CbVXyqoc1Y8&S=gift1

描述

对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。 然而,在任何一群朋友中,有些人将送出较多的礼物(可能是因为有较多的朋友),有些人有准备了较多的钱。 给出一群朋友,没有人的名字会长于 14 字符,给出每个人将花在送礼上的钱,和将收到他的礼物的人的列表, 请确定每个人收到的比送出的钱多的数目。

[编辑]格式

PROGRAM NAME: gift1

INPUT FORMAT:

(file gift1.in)

  • 第 1 行: 人数NP,2<= NP<=10
  • 第 2 行 到 第NP+1 行:这NP个在组里人的名字 一个名字一行
  • 第NP+2到最后:

这里的I段内容是这样组织的:

    • 第一行是将会送出礼物人的名字。
    • 第二行包含二个数字: 第一个是送出的钱的数目(在0到2000的范围里),第二个 NGi 是将收到这个人礼物的人的个数 如果 NGi 是非零的, 在下面 NGi 行列出礼物的接受者的名字,一个名字一行。

OUTPUT FORMAT:

(file gift1.out)

输出 NP 行

每行是一个的名字加上空格再加上收到的比送出的钱多的数目。

对于每一个人,他名字的打印顺序应和他在输入的2到NP+1行中输入的顺序相同。所有的送礼的钱都是整数。

每个人把相同数目的钱给每位要接受礼物的朋友,而且尽可能多给,不能给出的钱(即无法被整除的钱)由送礼者本人持有。

[编辑]SAMPLE INPUT

5davelauraowenvickamrdave200 3lauraowenvickowen500 1daveamr150 2vickowenlaura0 2amrvickvick0 0

[编辑]SAMPLE OUTPUT

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

/*
ID:
PROG: gift1
LANG: C++
*/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
struct node{
int first;
int second;
string name;
}nod[maxn];
bool cmp(int a,int b){
return a>b;
}
map<string,int >mp;
int main()
{
//#ifndef ONLINE_JUDGE
freopen("gift1.in","r",stdin);
//#endif
freopen("gift1.out","w",stdout);
int n;
while(cin>>n){
string s;
mp.clear();
for(int i=1;i<=n;i++){
cin>>s;
mp[s]=i;
nod[i].first=0;
nod[i].second=0;
nod[i].name=s;
}
int a,b;
string t;
for(int i=1;i<=n;i++){
//cout<<1<<endl;
cin>>s;
cin>>a>>b;
if(b==0)continue;
nod[mp[s]].first=a;
nod[mp[s]].second+=a%b;
int k=a/b;
for(int j=1;j<=b;j++){
cin>>t;
nod[mp[t]].second+=k;
}
}
for(int i=1;i<=n;i++){
cout<<nod[i].name<<" "<<nod[i].second-nod[i].first<<endl;
}
}
return 0;
}



0 0