Section 1.1 Greedy Gift Givers
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:
|
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的更多相关文章
- USACO Section 1.1-2 Greedy Gift Givers
Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...
- USACO Section 1.1 Greedy Gift Givers 解题报告
题目 问题描述 有若干个朋友,朋友之间可以选择互相赠送一些有价值的礼物.一个人可以选择将一部分钱分给若干个朋友,例如某人送给其他两个人钱,总共赠送3元,两个人平均分,原本应该是每人1.5元,但是只能取 ...
- USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers
P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- 119 - Greedy Gift Givers
Greedy Gift Givers The Problem This problem involves determining, for a group of gift-giving frien ...
- 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 ...
- Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- 洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
贪婪的送礼者Greedy Gift Givers 难度:☆ Code: #include <iostream> #include <cstdio> #include <c ...
- 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 ...
随机推荐
- UML中关联(Association)和依赖(Dependency)的区别
原文转自:http://blog.csdn.net/metasearch/article/details/2334853 在UMLCHINA精华区,看到了一些关联和依赖的讨论,似乎越讲越糊涂.我想谈一 ...
- JavaScript深入浅出补充——(一)数据类型,表达式和运算符
项目基本做完,在进行下一阶段学习之前先看视频学习回顾一下JavaScript 一.数据类型 JavaScript中有五种原始类型和一种对象类型 JavaScript弱类型语言中隐式转换 num-0 字 ...
- SQL SERVER 删除前判断指定的表或者存储过程是否存在
1.创建存储过程: CREATE PROCEDURE proc_pr ---将create修改成alter可以修改存储过程: AS BEGIN IF EXISTS(SELECT * FROM syso ...
- Tagged Pointer
前言 在2013年9月,苹果推出了iPhone5s,与此同时,iPhone5s配备了首个采用64位架构的A7双核处理器,为了节省内存和提高执行效率,苹果提出了Tagged Pointer的概念.对于6 ...
- gulp 入门指南
gulp 是基于 node 实现 Web 前端自动化开发的工具,利用它能够极大的提高开发效率. 在 Web 前端开发工作中有很多"重复工作",比如压缩CSS/JS文件.而这些工作都 ...
- JavaScript 语言中的 this
JavaScript 语言中的 this 由于其运行期绑定的特性,JavaScript 中的 this 含义要丰富得多,它可以是全局对象.当前对象或者任意对象,这完全取决于函数的调用方式.JavaSc ...
- win32SDK的hello,world程序(二)
接上篇,原生的控件都不太好看,所以决定自己画一个,稍微处理下消息就能用了.不过,美化这东西是需要天赋的.即使技术再好,没有对UI布局调整和良好的审美能力,做出来的东西还是很挫. 主要把消息逻辑和画的过 ...
- neo4j 数据库导入导出
工作中需要将 A 图数据库的数据完全导出,并插入到 B 图数据库中.查找资料,好多都是通过导入,导出 CSV 文件来实现.然而,经过仔细研究发现,导出的节点/关系 都带有 id 属性 ,因为 A B ...
- GitHub 入门教程
一.前言 编程进阶的道路是坎坷的,没有任何捷径.这个时期只能是积累.吸收.学习.坚持,做到量的积累,到质的飞跃 古语有云:'书山有路,勤为径'.'不积跬步,无以至千里' 编程是一个动手实践性的学科,多 ...
- 奔跑在Docker上的Spark
转自:马踏飞燕--奔跑在Docker上的Spark 目录 为什么要在Docker上搭建Spark集群 网络拓扑 Docker安装及配置 ssh安装及配置 基础环境安装 Zookeeper安装及配置 H ...