【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 ...
随机推荐
- 【环境】openSUSE安装记录 - 古董本上的windows 7和opensuse双系统
昨天和朋友交流,提到Linux,他说可以去接触SUSE.我马上打开浏览器搜索了一下,发现SUSE是一个Linux操作系统的企业服务器的发行版,是收费的.朋友说,许多公司都用这个,他曾经给公司安装过SU ...
- 深入分析windows下配置wamp环境各模块的版本兼容性
版本相关概念说明: ts/nts: thread safety 线程安全 TS refers to multithread capable builds. NTS refers to single t ...
- Dijkstra--POJ 2502 Subway(求出所有路径再求最短路径)
题意: 你从家往学校赶,可以用步行和乘坐地铁这两种方式,步行速度为10km/h,乘坐地铁的速度为40KM/h.输入数据的第一行数据会给你起点和终点的x和y的坐标.然后会给你数目不超过200的双向地铁线 ...
- linux install
http://www.ubuntu.org.cn/index_kylin 先在官网下个Ubuntu 是个iso 然后下个UltraISO 是个软件 插好空u盘 打开软件 在菜单栏上 点击 文件-&g ...
- silverlight的第一个程序
摘要:silverlight是微软公司全力打造的一种跨平台.跨浏览器的RIA新技术,silverlight以XAML为界面呈现语言,支持2D矢量图形.动画.数据绑定.控件风格与模板.LINQ.WCF. ...
- Linux安装Flash player
在线自动更新:Flash Player Update(需java) ===================== 下载得到install_flash_player_11_linux.x86_64.tar ...
- Codeforces Round #259 (Div. 2)-D. Little Pony and Harmony Chest
题目范围给的很小,所以有状压的方向. 我们是构造出一个数列,且数列中每两个数的最大公约数为1; 给的A[I]<=30,这是一个突破点. 可以发现B[I]中的数不会很大,要不然就不满足,所以B[I ...
- android SDK更新
在proxy.ini里的[profile]下加上如下配置即可更新android SDK了 dl-ssl.google.com = nofakehttps Oct 26, 2014 #2 2828qw. ...
- centos 安装软件
1)一种是软件的源代码,您需要自己动手编译它.这种软件安装包通常是用gzip压缩过的tar包(后缀为.tar.gz).2)另一种是软件的可执行程序,你只要安装它就可以了.这种软件安装包通常被是一个RP ...
- Delphi的Socket编程步骤
ClientSocket 和ServerSocket几个重要的属性: 1.client和server都有port属性,需要一致才能互相通信 2.client有Address属性,使用时填写对方 ...