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(贪心)的更多相关文章

  1. Gone Fishing(贪心)

    Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...

  2. POJ 1042 Gone Fishing#贪心

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...

  3. csu 1749: Soldiers ' Training(贪心)

    1749: Soldiers ' Training Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 37  Solved: 18[Submit][Stat ...

  4. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  5. 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...

  6. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  7. ACM学习历程—CSU 1216 异或最大值(xor && 贪心 && 字典树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1216 题目大意是给了n个数,然后取出两个数,使得xor值最大. 首先暴力枚举是C(n,  ...

  8. csu - 1538: Shopping (贪心)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1538 很奇妙的一个题,开始没有思路.问了别人才知道. 题目的意思可以理解成上图中,从0点开始向右走 ...

  9. HDU 6709“Fishing Master”(贪心+优先级队列)

    传送门 •参考资料 [1]:2019CCPC网络选拔赛 H.Fishing Master(思维+贪心) •题意 池塘里有 n 条鱼,捕捉一条鱼需要花费固定的 k 时间: 你有一个锅,每次只能煮一条鱼, ...

随机推荐

  1. 【紫书】uva489 Hangman Judge 做了很久Orz

    题目链接:https://vjudge.net/problem/UVA-489 题意:给出两行字符串,第一行是标准答案,第二行是玩家猜的串.玩家每次猜一个,猜对一个,标准答案中所有该字符都算被猜到.猜 ...

  2. windows hook 钩子

    windows  hook  钩子 场景: 1.打印机 Ctrl+P弹出支付窗口,付款成功后打印

  3. Improved SEO with mod_rewrite

    PHP Advanced and Object-Oriented Programming Third Edition <?php //D:\wamp64\www\0613pm\w_wwwroot ...

  4. [knowledge][linux][sysfs] sysfs文件系统

    https://en.wikipedia.org/wiki/Sysfs http://man7.org/linux/man-pages/man5/sysfs.5.html https://www.ke ...

  5. 玩具装箱&土地购买

    今天一天8h 写了两道斜率优化的题(别问我效率为什么这么低 代码bug太多了) 关键是思考的不周全 估计是写的题少手生 以后就会熟练起来了吧. 这道题显然有一个n^2的dp方程 设f[i]表示前i件物 ...

  6. Java之旅_高级教_集合框架

    摘自:http://www.runoob.com/java/java-collections.html Java 集合框架 早在Java2之前,java 就提供了特设类.比如:Dictionary,V ...

  7. 20165225 《Java程序设计》第二周学习总结

    20165225<Java程序设计>第二周学习总结 1.视频与课本中的学习: ##### 1.标识符: 字母.下划线.美元符号.数字(不能是true,false,null还有关键字). # ...

  8. 洛谷P3242 接水果 [HNOI2015] 整体二分

    正解:整体二分+树状数组 解题报告: 传送门! 题目还是大概解释下?虽然其实是看得懂的来着,,, 大概就是说给一棵树.给定一些询问,每个询问都是说在两个点之间的路径上的子路径的第k大是什么 然后看到这 ...

  9. C语言课堂题集

    1.输入一个整数,然后将其数字位置颠倒. int c,d=0,e; scanf("%d",&c); while (c!=0) { e=c%10; d=d*10+e; c/= ...

  10. Jenkins打包安卓时提示没同意constraintLayout的license的解决方法

    使用Jenkins打包安卓项目时,报错并失败,错误信息: You have not accepted the license agreements of the following SDK compo ...