USACO_1.1_Greedy_Gift_Givers_(模拟+水题)
描述
http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=gift1
给出不超过$10$个人,每个人拿出一定数量的钱平分给特定的人,求最后每个人的财产变化.
Task 'gift1': Greedy Gift Givers
A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts of money. Each of these friends might or might not give some money to some or all of the other friends (although some might be cheap and give to no one). Likewise, each friend might or might not receive money from any or all of the other friends. Your goal is to deduce how much more money each person receives than they give.
The rules for gift-giving are potentially different than you might expect. Each person goes to the bank (or any other source of money) to get a certain amount of money to give and divides this money evenly among all those to whom he or she is giving a gift. No fractional money is available, so dividing 7 among 2 friends would be 3 each for the friends with 1 left over – that 1 left over goes into the giver's "account". All the participants' gift accounts start at 0 and are decreased by money given and increased by money received.
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, no one of whom has a name longer than 14 characters,
- the money each person in the group spends on gifts, and
- a (sub)list of friends to whom each person gives gifts,
determine how much money each person ends up with.
IMPORTANT NOTE
The grader machine is a Linux machine that uses standard Unix conventions: end of line is a single character often known as '\n'. This differs from Windows, which ends lines with two characters, '\n' and '\r'. Do not let your program get trapped by this!
PROGRAM NAME: gift1
INPUT FORMAT
Line # | Contents | |||
---|---|---|---|---|
1 | A single integer, NP | |||
2..NP+1 | Line i+1 contains the name of group member i |
|||
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 by a single blank followed by the net gain or loss (final_money_value - initial_money_value) for that person. The names should be printed in the same order they appear starting on line 2 of the input.
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 that meets this constraint. Any money not given is kept by the giver.
SAMPLE OUTPUT (file gift1.out)
dave 302
laura 66
owen -359
vick 141
amr -150
分析
第二种写法貌似简短了些..
英文捉鸡QAQ
/*
TASK:gift1
LANG:C++
Time:2018.5.11-21:24
*/
#include <bits/stdc++.h>
using namespace std; const int maxn=,maxm=;
int n;
struct A{
char name[maxm+];
int m=;
}a[maxn+]; int main(){
freopen("gift1.in","r",stdin);
freopen("gift1.out","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%s",a[i].name);
for(int i=;i<n;i++){
char _x[maxm+];
int x,num,mon;
scanf("%s%d%d",_x,&mon,&num);
for(int j=;j<n;j++) if(!strcmp(_x,a[j].name)){
x=j;
break;
}
for(int j=;j<num;j++){
char _y[maxm+];
int y;
scanf("%s",_y);
for(int k=;k<n;k++) if(!strcmp(_y,a[k].name)){
y=k;
break;
}
int m=mon/num;
a[y].m+=m;
a[x].m-=m;
}
}
for(int i=;i<n;i++) printf("%s %d\n",a[i].name,a[i].m);
return ;
}
NO.1
/*
TASK:gift1
LANG:C++
Time:2018.5.11-21:35
*/
#include <bits/stdc++.h>
using namespace std; const int maxn=,maxm=;
int n;
struct B{
char name[maxm+];
int m=;
};
struct A{
B b[maxn+];
B& operator [] (const char* name){
for(int i=;i<n;i++) if(!strcmp(name,b[i].name)) return b[i];
}
B& operator [] (const int& i){
return b[i];
}
}a; int main(){
freopen("gift1.in","r",stdin);
freopen("gift1.out","w",stdout);
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%s",a[i].name);
for(int i=;i<n;i++){
char _x[maxm+];
int num,mon;
scanf("%s%d%d",_x,&mon,&num);
B& x=a[_x];
for(int j=;j<num;j++){
char y[maxm+];
scanf("%s",y);
int m=mon/num;
a[y].m+=m;
x.m-=m;
}
}
for(int i=;i<n;i++) printf("%s %d\n",a[i].name,a[i].m);
return ;
}
NO.2
USACO_1.1_Greedy_Gift_Givers_(模拟+水题)的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
题目链接:http://poj.org/problem?id=2864 题意:参照题目 哈哈哈,这个题discuss有翻译哦.水到我不想交了. #include <cstdio> #inc ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- HDU4287-STL模拟水题
一场2012天津网络预选赛的题,签到题. 但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决. 一开始用的Char [] 后来改成了string,STL和string搭配起来 ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- 模拟水题,牛吃草(POJ2459)
题目链接:http://poj.org/problem?id=2459 题目大意:有C头牛,下面有C行,每头牛放进草地的时间,每天吃一个草,总共有F1个草,想要在第D的时候,草地只剩下F2个草. 解题 ...
随机推荐
- 解决上传app store卡在正在通过iTunes Store鉴定
打开终端输入代码即可 cd ~ mv .itmstransporter/ .old_itmstransporter/ "/Applications/Xcode.app/Contents/Ap ...
- Eclipse中JS文件红叉处理
使用新版本的Eclipse 或者 MyEclipse,项目中的 JS文件出现红叉,让人觉得项目中存在错误代码,给人的感觉很不爽. 记录一下去掉红叉的方法: 第1步: 打开工作空间中的项目找到项目的 . ...
- Python 3基础教程17-提问频率较高的几个Python问题
这里,介绍几个初学者经常上网查询的问题,直接看下面的例子 # 常见的一些常识问题汇总 #!/user/bin/python # 这个是linux下python文件的写法,告诉程序,这个文件是pytho ...
- 【java并发编程】十三章:显式锁:LOCK
java5以后,新增了显式锁,用于当内置锁不能满足需求后可选择的一种高级方案. lock接口的特点 与内置锁一样,他能提供互斥性,内存可见性,可重入等特征,与内置锁不同的是,Lock提供了一种无条件, ...
- redis-Windows下安装与操作
Redis windows下安装 1.安装 (1)windows把redisbin_x32安装包放在电脑任意的盘里 (2)通过cmd找到对应目录: D\redisbin_x32 (3)开始安装 D\ ...
- 软件工程项目组Z.XML会议记录 2013/10/22
软件工程项目组Z.XML会议记录 [例会时间]2013年10月22日星期二21:00-22:30 [例会形式]小组讨论 [例会地点]三号公寓楼会客厅 [例会主持]李孟 [会议记录]周敏轩 会议整体流程 ...
- 【EasyNetQ】- 连接RabbitMQ
如果您习惯于处理与SQL Server等关系数据库的连接,那么您可能会发现EasyNetQ处理连接的方式有点奇怪.与关系数据库的通信始终由客户端启动.客户端打开连接,发出SQL命令,在必要时处理结果, ...
- WCF 动态调用(动态创建实例接口)
很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...
- thinkphp include处理加载重复出现的html页面
在网站设计经常用大量使用的html模板,例如header(一般是menu层甚至还带有图片轮播).left(后台管理页面比较常见的导航).footer(结尾层,一般也是小型的menu),使用includ ...
- Java中的输入输出流
FileInputStream和FileOutputStream 创建含磁盘文件的输入 输出流对象. FileInputStream继承自InputStream,用于读取本地文件中的字节数据,由于所有 ...