POJ1042 Gone Fishing
采用贪心策略。
假设他从1湖泊走到x 湖泊,这还剩下 h*12 - sigma(T1--Tx-1)。(单位时间为5分钟)。然后再用剩下的时间去钓1-x的湖泊的鱼。 每次都选择最多鱼的湖泊钓。
code:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 30; int f[maxn], tf[maxn], d[maxn], t[maxn], path[maxn];
int ans, p[maxn]; int main()
{
int h, n, i, j, k;
while(scanf("%d",&n),n) {
scanf("%d",&h);
h *= 12;
for(i=1; i<=n; ++i) scanf("%d",&f[i]);
for(i=1; i<=n; ++i) scanf("%d",&d[i]);
for(i=1; i<=n-1; i++) scanf("%d",&t[i+1]);
for(i=2,t[1]=0; i<=n; ++i) t[i] += t[i-1];
ans = -1000;
for(k=1; k<=n; ++k)
if(h>t[k]) {
int th = h - t[k];
int sum = 0;
memset(path, 0, sizeof path );
for(i=1; i<=n; ++i) tf[i] = f[i];
while(th>0) {
int maxx = 0;
int mark = 0;
for(i=1; i<=k; ++i)
if(maxx<tf[i]) {
maxx = tf[i];
mark = i;
}
if(!mark) break;
sum += maxx;
tf[mark] -= d[mark];
path[mark]++;
th--;
}
path[1] += th;
if(ans<sum) {
ans = sum;
for(j=1; j<=n; j++)
p[j] = path[j];
}
}
for(i=1; i<n; ++i) printf("%d, ",p[i]*5);
printf("%d\n",p[i]*5);
printf("Number of fish expected: %d\n\n", ans);
}
return 0;
}
POJ1042 Gone Fishing的更多相关文章
- ZOJ 1015 Fishing Net(弦图判定)
In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...
- bzoj 1242: Zju1015 Fishing Net 弦图判定
1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 214 Solved: 81[Submit ...
- Poj/OpenJudge 1042 Gone Fishing
1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...
- ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net
●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...
- Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent
Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
- Gone Fishing(贪心)
Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...
随机推荐
- 对话 UNIX: 关于 inode
http://www.ibm.com/developerworks/cn/aix/library/au-speakingunix14/ WMI http://wiki.hudson-ci.org/di ...
- json概述及python处理json等数据类型
<一,概念> 序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON.XML等.反序列化(deserialization): ...
- x/nfu-用gdb查看内存
用gdb查看内存 2007-12-08 12:43 用gdb查看内存 格式: x /nfu <addr> 说明x 是 examine 的缩写 n表示要显示的内存单元的个数 f表示显示方式, ...
- Swift中的集合类型
一.引子: 在2014年10月TIOBE编程语言排行榜中,Swift位居第18位,从2014WWDC发布会首次公布至今不到半年时间,swift一直受到编程人 员的追捧,其热衷程度并不亚于当红巨星Tay ...
- c++单元测试框架googletest
一.概述 Googletest是一个用来写C++单元测试的框架,它是跨平台的,可应用在windows.linux.Mac等OS平台上: 代码框架: [root@docker googletest-re ...
- mysql启动报错:Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
mysql在首次启动的时候可能会报错:Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist 这时候可以执行脚本 ...
- Oozie入门
作者 Boris Lublinsky, Michael Segel ,译者 侯伯薇 发布于 2011年8月18日 |注意:QCon全球软件开发大会(北京)2016年4月21-23日,了解更多详情! 分 ...
- 【IOS学习基础】NSObject.h学习
一.<NSObject>协议和代理模式 1.在NSObject.h头文件中,我们可以看到 // NSObject类是默认遵守<NSObject>协议的 @interface N ...
- c#中的数据类型简介(string)
Sting 字符串 引入话题 字符串是一个引用类型,从string数据类型的代码定义中也可以看出它实现了IEnumerable<char>接口和IEnumerable接口,因此字符串可以看 ...
- hadoop生态圈安装详解(hadoop+zookeeper+hbase+pig+hive)
-------------------------------------------------------------------* 目录 * I hadoop分布式安装 * II zoo ...