【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 ...
随机推荐
- Linux 硬盘分区、分区、删除分区、格式化、挂载、卸载
Linux 虽然一直都有在玩,但是对硬盘操作确实不是很熟悉今天有空,就整理了下. 1,创建分区 先查看下是否有磁盘没有分区 fdisk -l 其中第一个框和第二个框,是已经分好区的磁盘,第三个硬盘没有 ...
- Linux 下开放指定端口
安装tomcat后,在客户端输入地址 http://localhost:8080/ ,发现默认端口8080不能访问. 由于Linux防火墙默认是关闭8080端口.因此,若要能够访问8080端口,可以 ...
- Chapter 3 Discovering Classes and Object
Chatper 3 Discovering Classes and Object Exercises: 1.What is a class? A class is a template for man ...
- 《编写高质量代码:改善Java程序的151个建议》笔记
To fight the unthinkable,you have to be willing to do the unthinkable. 不要在循环中使用try catch,应该放在循环的外面 ...
- PP生产订单的BADI增强 WORKORDER_UPDATE
METHOD if_ex_workorder_update~before_update. *---------------------->增强1 开始* "当生产订单类型为PP01时, ...
- PHP数组的定义和遍历
//常用函数//生成随机数//echo rand(3,33); //两个参数来确定随机数的范围为3-33 //日期时间函数echo time(); //取当前时间的UNIX时间戳//date_defa ...
- MySQL基本概念
MySQL 数据库 MySQL可分为三个层次:文件层次,服务层次,界面 常用的数据类型:int 整数float double decimal ——小数(要在十进位栏里设置小数点后最大显示位数)varc ...
- 一个包的TcpServer流程
上次说到对于那种有内容的包 bool TCPServer::on_receive_data(int channel_id, void* data, int len) { packet pkt; { p ...
- SQLite中的日期基础
SQLite包含了如下时间/日期函数: datetime().......................产生日期和时间 date()...........................产生日期 t ...
- 1303: [CQOI2009]中位数图
早起一AC,整天萌萌哒. Problem: 1303 User: forgot93 Language: C++ Result: Accepted Time:56 ms Memory:2108 kb * ...