CSU 1859 Gone Fishing(贪心)
Gone Fishing
【题目链接】Gone Fishing
【题目类型】贪心
&题解:
这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = =
之后在枚举每个湖的鱼的个数,之后总是选最大的就好了,这里我是直接变的f数组,所以最后一定不要忘了在赋值回来
【时间复杂度】\(O(n^2k)\)
&代码:
#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn= 30 +9;
int n,h,f[maxn],K,ff[maxn],d[maxn],t[maxn];
vector<int> v1,v2;
int main()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
freopen("E:1.txt","r",stdin);
while(cin>>n){
if(K!=0) cout<<endl; K++;
if(n==0)break;
cin>>h; h*=12;
for(int i=0;i<n;i++) cin>>f[i],ff[i]=f[i];
for(int i=0;i<n;i++) cin>>d[i];
for(int i=1;i<n;i++) {cin>>t[i];t[i]+=t[i-1];}
int ans=0;
for(int i=0;i<n;i++) {
v2.clear(); v2.resize(n);
int tm=h-t[i];
// cout<<"tm="<<tm<<endl;
if(tm<0) break;
int a1=0;
for(int i=0;i<n;i++) f[i]=ff[i];
for(int o=0;o<tm;o++){
int ma=0,ps=0;
for(int j=0;j<=i;j++){
if(ma<f[j]){
ma=f[j];
ps=j;
}
}
// if(tm==10){
// cout<<"ps="<<ps<<" f[ps]="<<f[ps]<<endl;
// }
a1+=f[ps];
v2[ps]++;
f[ps]-=d[ps];
if(f[ps]<0) f[ps]=0;
}
if(ans<a1){
v1=v2;
ans=a1;
}
}
for(int i=0;i<n;i++){
cout<<v1[i]*5;
if(i!=n-1)cout<<", ";
}cout<<endl;
cout<<"Number of fish expected: "<<ans<<endl;
}
return 0;
}
CSU 1859 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 ...
- POJ 1042 Gone Fishing#贪心
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...
- csu 1749: Soldiers ' Training(贪心)
1749: Soldiers ' Training Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 37 Solved: 18[Submit][Stat ...
- uva757 - Gone Fishing(馋)
题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...
- 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
Gone Fishing Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 30281 Accepted: 9124 Des ...
- ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n, ...
- csu - 1538: Shopping (贪心)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走 ...
- HDU 6709“Fishing Master”(贪心+优先级队列)
传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...
随机推荐
- [No0000FC]C# 预处理器指令
预处理器指令指导编译器在实际编译开始之前对信息进行预处理. 所有的预处理器指令都是以 # 开始.且在一行上,只有空白字符可以出现在预处理器指令之前.预处理器指令不是语句,所以它们不以分号(;)结束. ...
- Java NIO 与 IO之间的区别
概述 Java NIO提供了与标准IO不同的IO工作方式: Channels and Buffers(通道和缓冲区):标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲 ...
- 关于Java的基础语法整理
- Lua 变量名词
UpValue Lua中的函数是一阶类型值(first-class value),定义函数就象创建普通类型值一样(只不过函数类型值的数据主要是一条条指令而已),所以在函数体中仍然可以定义函数.假设函数 ...
- AES加解密所遇问题
AES加解密后解密数据末尾携带多余空格,经查看是由于加密时数据不足16个字节自动补齐导致 解决办法:记录加密数据长度,解密后根据数据长度读取解密数据. 另外加密数据中可能存在0等数据,所以拷贝内容时最 ...
- 求助!使用 ReportViewer 控件集成 Reporting Services2008 时,报"...401 unauthorized"错误!
实现接口 public class ReportServiceCredetials : Microsoft.Reporting.WebForms.IReportServerCredentials { ...
- vivado SDK之找不到"platform.h"
解决方法:建工程的时候不要选择empty application,而是选择hello world,里面会自动包含platform.c,platform.h等. 另外,常用的xgpio.h头文件有时候 ...
- rm:删除目录和文件
[root@linux-node- sss]# rm soft.txt //删除文件 rm: remove regular empty file ‘soft.txt’? y [root@linux-n ...
- MySQL分支Percona
MySQL分支Percona 转载自:http://www.cnblogs.com/cevin/archive/2012/05/12/2496859.html 官方网站:http://www.perc ...
- wxPython:文本对话框TextEntryDialog
wxTextEntryDialog(wxWindow* parent, const wxString& message, const wxString& caption = " ...