【USACO】【Section1.1】Greedy Gift Givers
小白题,也没啥好说的。关键我的算法感觉特别菜的一点是每次要遍历数组从人名找对应的编号,这个效率就很低了。看了ANALYZE里面也是这样的。不过它比我好的一点是我多余设置了initial_money变量,确实是不需要的。还有一点就是有可能接受礼物的人是0个,要判断。如果是0就不用60~67行了,而且60行的分母也会为0;
/*ID:Moment1991
PROG:gift1
LANG:C++
Test 1: TEST OK [0.000 secs, 3504 KB]
Test 2: TEST OK [0.000 secs, 3504 KB]
Test 3: TEST OK [0.000 secs, 3504 KB]
Test 4: TEST OK [0.000 secs, 3504 KB]
Test 5: TEST OK [0.000 secs, 3504 KB]
Test 6: TEST OK [0.000 secs, 3504 KB]
Test 7: TEST OK [0.000 secs, 3504 KB]
Test 8: TEST OK [0.000 secs, 3504 KB]
Test 9: TEST OK [0.000 secs, 3504 KB] */
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
typedef struct PERSON{
char name[];
int intial_money;
int final_money;
}P;
P p[];
int np;
int find_pos(char person[])
{
for(int i =;i < np;i++)
{
//cout << person<<endl;
if(strcmp(person,p[i].name) == )
return i;
}
return -;
}
int main()
{
ifstream cin("gift1.in");
ofstream cout("gift1.out"); cin >> np;
for(int i = ;i <np;i ++)
{
cin >> p[i].name;
}
for(int i = ;i < np;i++)
{
char giver[];
int giver_money,receivers_num,each_money,giver_pos,receivers_pos;
char receiver[]; cin >> giver; giver_pos = find_pos(giver); cin >> p[giver_pos].intial_money;
cin >> receivers_num; if(receivers_num != ){
each_money = p[giver_pos].intial_money / receivers_num;
p[giver_pos].final_money -= each_money * receivers_num; for(int j = ;j < receivers_num;j++)
{
cin >> receiver;
receivers_pos = find_pos(receiver);
p[receivers_pos].final_money += each_money;
}
}
}
for(int i = ;i <np;i ++)
cout << p[i].name <<" "<<p[i].final_money<<endl;
}
【USACO】【Section1.1】Greedy Gift Givers的更多相关文章
- Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers
[USACO]1.1.2 贪婪的礼物送礼者 Greedy Gift Givers 题目描述 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for th ...
- 洛谷 P2812 校园网络【[USACO]Network of Schools加强版】 解题报告
P2812 校园网络[[USACO]Network of Schools加强版] 题目背景 浙江省的几所OI强校的神犇发明了一种人工智能,可以AC任何题目,所以他们决定建立一个网络来共享这个软件.但是 ...
- 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 ...
- USACO Section 1.1-2 Greedy Gift Givers
Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...
- 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 ...
- Greedy Gift Givers 贪婪的送礼者 USACO 模拟
1002: 1.1.2 Greedy Gift Givers 贪婪的送礼者 时间限制: 1 Sec 内存限制: 128 MB提交: 9 解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...
- 119 - Greedy Gift Givers
Greedy Gift Givers The Problem This problem involves determining, for a group of gift-giving frien ...
- Section 1.1 Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts o ...
- 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 ...
随机推荐
- SQL Server数据库与max degree of parallelism参数
我们今天主要向大家讲述的是SQL Server数据库中的max degree of parallelism参数,当 SQL Server 数据库在具N个微处理器或是 CPU 的计算机上运行时,它将为每 ...
- Ngrok 内网穿透神器(转载)
mac上配置web服务: http://note.rpsh.net/posts/2013/11/27/osx-10-9-apache-server-php-mysql/ Ngrok 内网穿透神器 由于 ...
- Grails 对象关联映射 (GORM) 一
转自:http://justjavac.iteye.com/blog/701445 Domain 类是任何商业应用的核心. 他们保存事务处理的状态,也处理预期的行为. 他们通过关联联系在一起, one ...
- rtsp实时流通过rtmp推送到服务端
很多朋友都会问到rtsp如何通过rtmp协议推送到服务端,正好前段时间开发了这个功能写在这里,和大家分享下. 首先我想说的是:ffmpeg可以实现这个功能.ffmpeg支持rtsp协议,也支持rtmp ...
- IOS 8 关于 Touch ID
一.什么是Touch ID? Touch ID是在iPhone 5s后的设备上出现的指纹识别.Apple在IOS 8中开放给第三方APP使用. 可以使用 Touch ID 来验证用户的身份,用户经验证 ...
- BZOJ3438 小M的作物
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3438 这题觉得和上题有点类似吧. 如果没有联合在一起的收成,可以比较好做[我们将属于A的表 ...
- 【BZOJ】【1059】【ZJOI2007】矩阵游戏
二分图完美匹配/匈牙利算法 如果a[i][j]为黑点,我们就连边 i->j ,然后跑二分图最大匹配,看是否有完美匹配. <_<我们先考虑行变换:对于第 i 行,如果它第 j 位是黑点 ...
- KMP_Best Reward
大意:把一个字符串分成两串,假如一个字符串是回文串就可以加上它的VALUE,否则它的VALUE为0: KMP的特点是可以求出前缀与后面的字符串是否匹配, 注意回文串的特点,所以当我们把回文串反转的时候 ...
- Sqli-labs less 24
Less-24 Ps:本关可能会有朋友和我遇到一样的问题,登录成功以后没有修改密码的相关操作.此时造成问题的主要原因是logged-in.php文件不正确.可重新下载解压,解压过程中要主要要覆盖. 本 ...
- Sqli-labs less 25a
Less-25a 不同于25关的是sql语句中对于id,没有''的包含,同时没有输出错误项,报错注入不能用.其余基本上和25示例没有差别.此处采取两种方式:延时注入和联合注入. http://127. ...