Greedy Gift Givers

A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts of money. Each of these friends might ormight not give some money to any or all of the other friends.Likewise, each friend might or might not receive money from any orall 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 youmight expect. Each person sets aside a certain amount of money togive and divides this money evenly among all those to whom he orshe is giving a gift. No fractional money is available, so dividing3
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 moremoney than others.

Given a group of friends, no one of whom has a name longer than14 characters, the money each person in the group spends on gifts,and a (sub)list of friends to whom each person gives gifts, determinehow much more (or less) each person in the group gives than
theyreceive.

IMPORTANT NOTE

The grader machine is a Linux machine that uses standard Unixconventions: 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!

PROGRAM NAME: gift1

INPUT FORMAT

Line 1: The single integer, NP
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.
The second line in the group contains two numbers: The initialamount of money (in the range 0..2000) to be divided up into gifts by the giverand then the number of people to whom the giver will give gifts,NGi (0 ≤ NGi ≤ NP-1).
If NGi is nonzero, each of the next NGi lines lists the the name of a recipient of a gift.

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 bya single blank followed by the net gain or loss (final_money_value - initial_money_value) for that person. The names should be printed inthe same order they appear on line 2 of the input.

All gifts are integers. Each person gives the same integer amountof money to each friend to whom any money is given, and gives as muchas possible that meets this constraint. Any money not given is kept bythe giver.

SAMPLE OUTPUT (file gift1.out)

dave 302
laura 66
owen -359
vick 141
amr -150 此题关键在于如何处理字符串所表示人的名字上,就是如何通过一个名字找到此人的位置,下面写了find()函数 用于返回名字所在的位置
/*
ID: ifayne1
LANG: C++
TASK: gift1
*/
#include <iostream>
#include <stdio.h>
#include <string> #define NP 11 using namespace std; struct _NP{
string name;
int have;
}N[NP]; int n; int find(string name)
{
int i;
for ( i=0; i<n; i++ )
{
if ( name == N[i].name ) break;
}
return i;
} void input()
{
int amount, divide;
string temp;
cin >> temp;
cin >> amount >> divide;
if ( divide != 0 )
{
N[find(temp)].have = N[find(temp)].have - (amount - amount % divide);
for ( int i=0; i<divide; i++ )
{
cin >> temp;
N[find(temp)].have += (amount / divide);
}
}
} int main()
{
freopen("gift1.in", "r", stdin);
freopen("gift1.out", "w", stdout);
int i;
cin >> n;
for ( i=0; i<n; i++ )
{
cin >> N[i].name;
N[i].have = 0;
}
for ( i=0; i<n; i++ )
input();
for ( i=0; i<n; i++ )
cout << N[i].name << " " << N[i].have << endl;
return 0;
}

Section 1.1 Greedy Gift Givers的更多相关文章

  1. USACO Section 1.1-2 Greedy Gift Givers

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

  2. USACO Section 1.1 Greedy Gift Givers 解题报告

    题目 问题描述 有若干个朋友,朋友之间可以选择互相赠送一些有价值的礼物.一个人可以选择将一部分钱分给若干个朋友,例如某人送给其他两个人钱,总共赠送3元,两个人平均分,原本应该是每人1.5元,但是只能取 ...

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

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

  4. USACO . Greedy Gift Givers

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

  5. 119 - Greedy Gift Givers

     Greedy Gift Givers  The Problem This problem involves determining, for a group of gift-giving frien ...

  6. 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 ...

  7. Greedy Gift Givers

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

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

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

  9. 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 ...

随机推荐

  1. Chapter 7. Design and Performance

    本章将对MPEG4及H.264的实现细节进行讲解和比对. Motion Estimation 衡量运动估计的好坏有三种函数(第228页):MSE,MAE和SAE,其中由于SAE运算速度最快所以采用的最 ...

  2. word2-寻找社交新浪微博中的目标用户

    项目简述: 为了进行更加精准的营销, 利用数据挖掘相关算法, 利用开放API或自行编写爬虫获得新浪微博, 知乎等社交网络(可能需要破解验证码)中用户所发布的数据, 利用数据挖掘的相关算法进行分析, 从 ...

  3. HTML基本结构与标签总结整理篇

    HTML基本结构与标签总结整理篇 前言:这是笔者的学习总结与整理,如果有错误或疑问的地方,欢迎指正与讨论!另:此文会不定时更新~ 1.了解HTML 学习前端技术,必然涉及三个方面:html(结构).c ...

  4. 【原】Sql Server 2008---安装时卸载Visual Studio

    由于数据库连接不上,所以卸载数据库,然后安装的时候出问题报错,结果是因为vs, 所以就有了卸载vs这一步.某些图片借用一下. 1. 打开电脑中的控制面板--程序和功能 2.找到要卸载的软件,但是卸载过 ...

  5. ASP.NET Core 源码学习之 Logging[1]:Introduction

    在ASP.NET 4.X中,我们通常使用 log4net, NLog 等来记录日志,但是当我们引用的一些第三方类库使用不同的日志框架时,就比较混乱了.而在 ASP.Net Core 中内置了日志系统, ...

  6. P2286 [HNOI2004]宠物收养场

    题目描述 凡凡开了一间宠物收养场.收养场提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物. 每个领养者都希望领养到自己满意的宠物,凡凡根据领养者的要求通过他自己发明的一个特殊的公式,得出该领 ...

  7. 如何查看安装的sql server是什么版本

    方法 1:通过使用 SQL Server Management Studio 中的对象资源管理器连接到服务器.连接对象资源管理器后,它将显示版本信息(在括号中),以及用于连接到 SQL Server ...

  8. [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)

    Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...

  9. Python爬虫从入门到放弃(十三)之 Scrapy框架的命令行详解

    这篇文章主要是对的scrapy命令行使用的一个介绍 创建爬虫项目 scrapy startproject 项目名例子如下: localhost:spider zhaofan$ scrapy start ...

  10. JMeter Plugin插件配置及远程监控

    下载jmeter plugins 插件: https://jmeter-plugins.org/downloads/all/ 官网建议我们直接下载plugins-manager.jar,然后进行可选择 ...