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 ...
随机推荐
- zoom与scale的异同
zoom与scale的异同点 作为一名前端,尤其是页面要兼容ie浏览器的前端,肯定对着两个属性都很熟悉. zoom和scale都是css中常用的放大和缩小一个元素的方法,在scale还没有成为css3 ...
- python 导入informixdb模块
最近碰到Linux平台使用python连接informixdb数据库的问题.整理如下: 1.安装 informixdb 下载InformixDB-2.5.tar.gz 解压之后,在README文档下看 ...
- linux查询进程号,出现两个进程
[root@ADM01B ~]# ps -ef|grep iesmgr root 5929 5321 0 09:38 pts/7 00:00:00 grep iesmgr root 9798 1 0 ...
- jq-animate
jq-animate: <!doctype html> <html> <head> <meta charset="utf-8"> & ...
- 教你如何取消GCD任务
GCD 是一种非常方便的使用多线程的方式.通过使用 GCD,我们可以在确保尽量简单的语法的前提下进行灵活的多线程编程.在 "复杂必死" 的多线程编程中,保持简单就是避免错误的金科玉 ...
- 100+个MySQL调试和优化技巧
MySQL是一个功能强大的开源数据库.随着越来越多的数据库驱动的应用程序,人们一直在推动MySQL发展到它的极限.这里是101条调节和优化MySQL安装的技巧.一些技巧是针对特定的安装环境的,但这些思 ...
- 添加zabbix自动发现(监控多tomcat实例)
说明 何为自动发现?首先我们监控多tomcat实例,如果一个个实例地添加或许可以完成当前需求.但是日后随着实例的增多,再手动一个个去添加就十分不方便了.这时候需要自动发现这个功能,来帮助我们自动添加监 ...
- Python基础之常用模块(二)
一.sys模块 1.sys.exit() 退出程序,这是正常退出程序,与之前用的break不同的是,break只是退出循环,循环之后的代码还会正常运行 2.sys.argv 会返回一个列表,列表中的 ...
- DNS,TCP,IP,HTTP,socket,Servlet概念整理
DNS,TCP,IP,HTTP,socket,Servlet概念整理 常见的协议虽然很容易理解,但是看了之后过一段时间不看还是容易忘,笔记如下,比较零碎,勉强供各位复习.如有错误欢迎指正. D ...
- Java虚拟机--垃圾收集
Java虚拟机 1. JVM运行时数据区域 参考书籍:<深入理解Java虚拟机:JVM高级特性与最佳实践,第二版> 资料参考:http://blog.csdn.net/nms312/art ...