贪心 - poj1042 Gone Fishing
来源:互联网 发布:微信改单是什么软件 编辑:程序博客网 时间:2024/05/22 15:50
题目:
http://poj.org/problem?id=1042
题意:
某君去钓鱼,有h个小时的时间,n个渔场只能按编号顺序走,每次钓鱼需耗费5分钟,每个渔场每次钓到的鱼期望数量随次数增加递减,已知每个渔场初始期望fi,递减期望di,每个渔场间的距离所需时间ti,问最大期望鱼数,以及在每个渔场耗费的时间
思路:
枚举钓鱼过程中到达的渔场的最大编号N,最大编号确定后,在路上耗费的时间就确定了,在[1,N]间的渔场钓鱼等于瞬移,每次贪心取最大期望即可
代码:
#include<stdio.h>#include<iostream>#include<string>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<map>#include<set>#include<functional>#pragma comment(linker, "/STACK:102400000,102400000")//C++using namespace std;const double PI = 3.141592653589793238462643383279502884197169399;const int MAXINT = 0x7fffffff;const int MAXSIZE = 25 + 5;struct node{int num, fish;};//最大堆bool operator <(const node&p1, const node&p2){if (p1.fish==p2.fish) return p1.num>p2.num;return p1.fish<p2.fish;}priority_queue<node> q;int main(){ int n; int h; int f[MAXSIZE]; int d[MAXSIZE]; int t[MAXSIZE]; int ans[MAXSIZE][MAXSIZE]; while (cin>>n,n!=0){ memset(ans,0,sizeof(ans)); cin>>h; h*=12; for (int i=0;i<n;++i) cin>>f[i]; for (int i=0;i<n;++i) cin>>d[i]; for (int i=0;i<n-1;++i) cin>>t[i]; //in int maxFish=0,maxAns=0; for (int i=0;i<n;++i){ int ti=h; for (int k=1;k<=i;++k) ti-=t[k-1]; if (ti<0) break; //cout<<i<<" "<<ti<<endl; while (!q.empty()) q.pop(); for (int k=0;k<=i;++k){ node temp={k,f[k]}; q.push(temp); } int sum=0; while (ti){ if (q.top().fish<=0) break; ti--; node temp=q.top(); q.pop(); ++ans[i][temp.num]; sum+=temp.fish; temp.fish-=d[temp.num]; q.push(temp); } if (ti) ans[i][0]+=ti; if (sum>maxFish){ maxFish=sum; maxAns=i; } } for (int i=0;i<n;++i){ cout<<ans[maxAns][i]*5; if (i!=n-1) cout<<", "; } cout<<endl; cout<<"Number of fish expected: "<<maxFish<<endl<<endl; } return 0;}
0 0
- POJ1042 Gone Fishing(贪心)
- POJ1042 Gone Fishing 贪心
- 【贪心】poj1042 Gone Fishing
- poj1042 Gone Fishing 贪心
- POJ1042 Gone Fishing贪心
- 贪心 - poj1042 Gone Fishing
- Gone Fishing(Poj1042)(贪心+枚举)
- POJ1042 Gone Fishing
- POJ1042 Gone Fishing
- POJ1042 Gone Fishing
- 1207#POJ1042 Gone Fishing
- 【POJ1042】Gone Fishing 黑书上第一道贪心题。
- [解题报告]POJ1042 Gone Fishing
- 【解题报告】poj1042 Gone Fishing
- 1042 Gone Fishing //贪心
- gone fishing 贪心
- 贪心--Gone Fishing
- POJ 1042 Gone Fishing(贪心)
- JAVA 中 static 的理解
- WeifenLuo.WinFormsUI.Docking.dll使用
- 一些问题(未解决)
- tomcat 产生heapdump文件配置
- 如何备考新GRE阅读客观题
- 贪心 - poj1042 Gone Fishing
- xcode6模拟器不显示键盘解决方案
- Android开发中java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx}: java.lang.NullPoi
- PHP面向对象编程之--继承
- Android.mk添加第三方jar包
- MyEclipse10 中的两种FreeMarker插件的安装与配置
- iOS手势
- ckeditor使用记录
- Android Studio开发入门-引用jar及so文件