LightOJ1106 Gone Fishing
Gone Fishing
John is going on a fishing trip. He has h hours available, and there are n lakes in the area all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i (1 to n-1), the number of 5-minute intervals it takes to travel from lake i to lake i+1 is denoted ti. For example, t3=4 means that it takes 20 minutes to travel from lake 3 to 4.
To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi, is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di. If the number of fish expected to be caught in an interval is less than or equal to di, there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch. Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing two integers n (2 ≤ n ≤ 25) and h (1 ≤ h ≤ 16). Next, there is a line of n integers specifying fi (0 ≤ fi ≤ 1000), then a line of n integers di (0 ≤ di ≤1000), and finally, a line of n-1 integers denoting ti (0 < ti < 192).
Output
For each test case, print the case number first. Then print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught. This is followed by a line containing the number of fish expected. If multiple plans exist, choose the one that spends as long as possible at lake 1. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on.
Sample Input
3
2 1
10 1
2 5
2
4 4
10 15 20 17
0 3 4 3
1 2 3
4 4
10 15 50 30
0 3 4 3
1 2 3
Sample Output
Case 1:
45, 5
Number of fish expected: 31
Case 2:
240, 0, 0, 0
Number of fish expected: 480
Case 3:
115, 10, 50, 35
Number of fish expected: 724
好奇怪的题
看上去像是背包,后来发现似乎时间不够
然后发现可以枚举停在哪里,然后用堆维护在1到k钓鱼的时候怎么钓
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
int n,m,ans,len;
int v[],w[],t[];
int f[];
int sv[];
int wk[];
priority_queue<pa,vector<pa>,greater<pa> >q;
inline void solve(int k)
{
while (!q.empty())q.pop();
memset(wk,,sizeof(wk));
for (int i=;i<=k;i++)q.push(mkp(-v[i],i));
int rest=m-t[k],sum=;
if (rest<=)return;
while (rest&&!q.empty())
{
int v=-q.top().first,id=q.top().second;
//printf("q %d %d\n",v,id);
q.pop();
sum+=v;
wk[id]++;
if (v>w[id])q.push(mkp(-(v-w[id]),id));else q.push(mkp(,id));
rest--;
}
if (sum>ans){len=k;ans=sum;for (int i=;i<=n;i++)sv[i]=wk[i];return;}
if (sum<ans)return;
bool mrk=;
for (int i=;i<=k;i++)
{
if (wk[i]>sv[i])mrk=;
if (wk[i]!=sv[i])break;
}
if (mrk){len=k;ans=sum;for (int i=;i<=n;i++)sv[i]=wk[i];return;}
return;
}
inline void work(int cur)
{
n=read();m=read()*;
memset(sv,,sizeof(sv));
ans=;
for (int i=;i<=n;i++)v[i]=read();
for (int i=;i<=n;i++)w[i]=read();
for (int i=;i<=n;i++)t[i]=read()+t[i-];
for (int i=;i<=n;i++)solve(i);
printf("Case %d:\n",cur);
for (int i=;i<n;i++)printf("%d, ",*sv[i]);
printf("%d\n",*sv[n]);
printf("Number of fish expected: %d\n",ans);
}
int main()
{
int T=read(),tt=;while (T--)work(++tt);
}
LightOJ 1106
LightOJ1106 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 ...
随机推荐
- Maven添加本地依赖
在写本文的时候先来说明一下maven依赖的各种范围的意思 compile(编译范围) compile 是默认的范围:如果没有提供一个范围,那该依赖的范围就是编译范围.编译范围依赖在所有的c ...
- CocoaPods 安装使用
CocoaPods是一个负责管理iOS项目中第三方开源代码的工具.CocoaPods项目的源码在Github上管理.该项目开始于2011年8月 12日,经过一年多的发展,现在已经超过1000次提交,并 ...
- chrom控制台常用方法
console.assert对输入的表达式进行断言,只有表达式为false时,才输出相应的信息到控制台 . console.count(这个方法非常实用哦)当你想统计代码被执行的次数 console. ...
- linux_1
注: 创建软连接: "ln -s xxx 路径1" 在路径1创建xxx的软连接 特点: 1.文件类型 l 2.相当于windows的快捷方式 创建硬链接: "ln xxx ...
- JsonUtils工具类
public class JsonUtils { public static void printTimeObject(Object obj, HttpServletResponse response ...
- 连接器前置挂载U盾
连接器前置挂载U盾 1. 宿主机配置及其信息 虚拟化软件版本 主机名 宿主机IP 账号及其密码 WorkStation windows idca- vm01 172.16.6.30 * Qemu-kv ...
- Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载
首先,找齐Spring框架中IoC功能.aop功能.JdbcTemplate功能所需的jar包,当前13个Jar包 1.Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或 ...
- javascript获取属性的两种方法及区别
javascript获取属性有两种方式,点或者中括号: var obj={} obj.x=1 console.log(obj.x)//1 第一种方式,x是字面量 try{ console.log(ob ...
- Mac OS 终端强化美化:iterm2 + zsh + oh~my~zsh 设置教程
为了获得更好的排版效果,文章改用markdown撰写,故重发一次. 前言 mac自带的terminal终端没有文件名高亮等功能,而且界面不是很好看,故今晚学舍友折腾了终端,可以让自己使用起来更加方便, ...
- Centos6.9 搭建rsync服务端与客户端 案例:全网备份项目
rsync的企业工作场景说明 1)定时备份 1.1生产场景集群架构服务器备份方案项目 借助cron+rsync把所有客户服务器数据同步到备份服务器 2)实时复制 本地数据传输模式(local-only ...