POJ 1042 解题报告
来源:互联网 发布:淘宝网拖鞋 编辑:程序博客网 时间:2024/05/01 13:26
这道题最好的解释在这里:http://blog.csdn.net/ju136/article/details/6957771
这里不再赘述。总之就是贪心加枚举。
对于“Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval” 这句话的理解应该是:如果不在该lake上面钓鱼,那么该lake里面的鱼是不会减少的,只有当选择了该lake,那么鱼会稳定减少直至为0。
这样,先减去路上(从a到b)的时间,第一和第三时间段选a,第二时间段选b,和第一二时间段选a,路上花去从a到b的时间,第三时间段选b是一样的。
实现上讲,priority_queue(heap)比set好,具体分析见:http://stackoverflow.com/questions/10141841/difference-between-stdset-and-stdpriority-queue
/* ID: thestor1 LANG: C++ TASK: poj1042 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXN = 25;class Lake{public:int lakeno;int fishnum;Lake(int lakeno, int fishnum){this->lakeno = lakeno;this->fishnum = fishnum;}inline bool operator< (const Lake& rhs) const {return this->fishnum < rhs.fishnum || (this->fishnum == rhs.fishnum && this->lakeno > rhs.lakeno);}};int main(){int fi[MAXN], di[MAXN], ti[MAXN - 1];int fishtimeperlake[MAXN], optimalfishtimeperlake[MAXN];int totoalfishnum, maxtotalfishnum;int n, h;while (scanf("%d", &n) && n){scanf("%d", &h);// hours to no. of 5 minutesh *= 12;for (int i = 0; i < n; ++i){scanf("%d", &fi[i]);}for (int i = 0; i < n; ++i){scanf("%d", &di[i]);}for (int i = 0; i < n - 1; ++i){scanf("%d", &ti[i]);}// initially, the best thing is staying at the first lake all the timememset(optimalfishtimeperlake, 0, n * sizeof(int));optimalfishtimeperlake[0] = h;maxtotalfishnum = 0;int timeintravel = 0, lastlakeno = 0;while (timeintravel < h && lastlakeno < n){int fishtime = h - timeintravel;memset(fishtimeperlake, 0, n * sizeof(int));priority_queue<Lake> que;for (int i = 0; i <= lastlakeno; ++i){que.push(Lake(i, fi[i]));}totoalfishnum = 0;for (int fishtimeinterval = 0; fishtimeinterval < fishtime; ++fishtimeinterval){Lake lake = que.top();que.pop();totoalfishnum += lake.fishnum;fishtimeperlake[lake.lakeno]++;// reduce fishnum in this lakelake.fishnum -= di[lake.lakeno];if (lake.fishnum < 0){lake.fishnum = 0;}que.push(lake);}if (totoalfishnum > maxtotalfishnum){maxtotalfishnum = totoalfishnum;memcpy(optimalfishtimeperlake, fishtimeperlake, n * sizeof(int));}timeintravel += ti[lastlakeno];lastlakeno++;}for (int i = 0; i < n; ++i){// the time interval is 5 minutesprintf("%d", 5 * optimalfishtimeperlake[i]);if (i != n - 1){printf(", ");}else{printf("\n");}}printf("Number of fish expected: %d\n\n", maxtotalfishnum);}return 0;}
0 0
- POJ 1042 解题报告
- POJ 1042 解题报告
- poj-openjudge 1042:Moles 解题报告
- poj解题报告——1042
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- python自然语言处理nltk库常用接口
- C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站
- 博弈问题入门
- 揭秘风水师:最高年入百万 客户有市委书记等高官
- Path相关方法讲解(一)
- POJ 1042 解题报告
- PLSQL Developer连接Oracle11g 64位数据库配置详解
- wordnet的特点
- [leetcode] 63.Unique Paths II
- ubuntu添加程序到启动器
- 揭秘风水师:最高年入百万 客户有市委书记等高官
- handler机制的原理
- 为想学SQLite或练习SQL语言的朋友搭建简单的命令行环境------在Windows, Linux, Android(用adb连接安卓手机)上玩转SQLite数据库的sqlite3命令行
- java函数传参方式理解