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 ...
随机推荐
- OPENFIRE 接收数据流程图
此图网上已经有,怎奈我不能上传大于10M的图片,所以截图了!各位请脑补!
- 远程linux服务器mysql数据库定期备份和删除
网上已经有部分关于Linux下定期备份mysql的方法,但是很多步骤不够详细,不适合新手,自己琢磨了很久,终于搞定了. 1.Linux服务器一般是ssh协议,如果本地也是Linux环境,可以直接通过s ...
- 洛谷 P2483 [SDOI2010]魔法猪学院
题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世界的世界本原有了很多的了解:众所周知,世界是由元素构成的:元素与 ...
- strongSwan大坑一直重启(ubuntu)
报错 Starting strongSwan 5.3.2 IPsec [starter]... charon (20533) started after 40 ms charon stopped af ...
- 爬虫学习之pdf读取和存储
在py3中如需进行pdf文件操作需要加载PDFMiner3K库文件,可通过pip方式或者可以下载源文件方式安装 python3 -m pip install pdfminer3k 下载源文件方式: 1 ...
- var、let、const声明变量的区别
let和var声明变量的区别:1.let所声明的变量只在let命令所在的代码块内有效.(块级作用域) for(let i=0;i<10;i++){ // ... } console.log(i) ...
- ubuntu 18.* 重启网卡
systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting A ...
- java数字金额转化为中文金额
public static String digitUppercase(double n){String fraction[] = {"角", "分"};Str ...
- [LUOGU] 1002 过河卒
题目描述 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之为"马拦过 ...
- tkinter学习-事件绑定与窗口
阅读目录: 事件绑定 Toplevel组件 标准对话框 事件绑定: 说明:对于每个组件来说,可以通过bind()方法将函数或方法绑定到具体的事件上. 事件序列: 说明:用户需要使用bind()方法将具 ...