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. 量子杨-Baxter方程新解系的一般量子偶构造_爱学术 https://www.ixueshu.com/document/f3385115a33571aa318947a18e7f9386.html

    量子杨-Baxter方程新解系的一般量子偶构造_爱学术 https://www.ixueshu.com/document/f3385115a33571aa318947a18e7f9386.html

  2. =[Mathematics] 数学主题

    https://www.douban.com/group/maths/ 圆锥体体积公式的证明

  3. nohup 和 &

    &的意思是在后台运行, 什么意思呢?  意思是说, 当你在执行 ./a.out & 的时候, 即使你用ctrl C,  那么a.out照样运行(因为对SIGINT信号免疫). 但是要注 ...

  4. Django 之Redis配置

    目的:访问服务器频繁的读取数据库 ,会耗损服务器性能及降低用户体验,为此引入Redis 1,安装 redis(2.10.6兼容性更好) pip install redis 2,settings.py配 ...

  5. django上下文处理器

    上下文处理器(context processors)上下文处理器是可以返回一些数据,在全局模板中都可以使用.比如登录后的用户信息,在很多页面中都需要使用,那么我们可以放在上下文处理器中,就没有必要在每 ...

  6. CF997C Sky Full of Stars 数论

    正解:容斥 解题报告: 传送门! 两个方法,分别港下QAQ 先说第一种 首先要推出式子,就∑2*C(i,n)*(-1)i+1*3i*3n*n-n+3*∑∑(-1)i+j+1*C(i,n)*C(j,n) ...

  7. HD200703

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  8. Spring JPA实现逻辑源码分析总结

    1.SharedEntityManagerCreator: entitymanager的创建入口 该类被EntityManagerBeanDefinitionRegistrarPostProcesso ...

  9. Docker 镜像(五)

    我们都知道,操作系统分为内核和用户空间.对于 Linux 而言,内核启动后,会挂载 root 文件系统为其提供用户空间支持.而 Docker 镜像(Image),就相当于是一个 root 文件系统.比 ...

  10. 20170720 Celery 异步任务处理到Sql Server 发生死锁

    -- 1.  异常提示情况如下: 需要解决为什么引起死锁 -- 叹气 原因: 在使用Celery 启用了 配置参数 CELERYD_CONCURRENCY = 10  表示开了10块线程池. 有好处, ...