题目大意:John有h的时间可以去钓鱼,有n湖可钓鱼,以5分钟为时间单位,每个湖初始每个单位时间可钓f条鱼,每下一个时间单位数量减少d条。同时,John只能从1号湖往后走进行钓鱼,湖之间的距离需要t个单位时间。求最多能钓到最多少鱼,并给出方案。

  “贪心+暴力,从近至远依次枚举可以到达的钓鱼地点,用总时间减去中途消耗的时间,这样就可以将其当成在各个钓鱼地点之间随意转移(实际题目中给出是单方向前行的),然后在已到达的最远的钓鱼地点之内的所有钓鱼地点上按每次能钓到的鱼的最大值做贪心,若时间用不完,则剩余时间加到第一个钓鱼地点上。注意,钓鱼地点最初的钓鱼值可能为零。”

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <queue>
  4. using namespace std;
  5. #define MAXN 30
  6.  
  7. struct Lake
  8. {
  9. int id, f;
  10. bool operator < (const Lake& l) const
  11. {
  12. if (f != l.f) return f < l.f;
  13. else return id > l.id;
  14. }
  15. };
  16.  
  17. int f[MAXN], d[MAXN], t[MAXN], fish[MAXN], res[MAXN];
  18.  
  19. int main()
  20. {
  21. #ifdef LOCAL
  22. freopen("in", "r", stdin);
  23. #endif
  24. int n;
  25. bool first = true;
  26. while (scanf("%d", &n) && n)
  27. {
  28. int h;
  29. scanf("%d", &h);
  30. for (int i = ; i < n; i++)
  31. scanf("%d", &f[i]);
  32. for (int i = ; i < n; i++)
  33. scanf("%d", &d[i]);
  34. t[] = ;
  35. for (int i = ; i < n; i++)
  36. {
  37. scanf("%d", &t[i]);
  38. t[i] += t[i-];
  39. }
  40. int ans = -;
  41. for (int i = ; i < n; i++) // the last lake arrived
  42. {
  43. int time = h * ;
  44. if (t[i] > time) break;
  45. time -= t[i];
  46. priority_queue<Lake> q;
  47. Lake tmp;
  48. for (int j = ; j <= i; j++)
  49. if (f[j])
  50. q.push( (Lake){j, f[j]} );
  51. memset(fish, , sizeof(fish));
  52. int sum = ;
  53. while (!q.empty() && time > )
  54. {
  55. tmp = q.top();
  56. q.pop();
  57. sum += tmp.f;
  58. int id = tmp.id;
  59. fish[id]++;
  60. time--;
  61. tmp.f -= d[id];
  62. if (tmp.f > ) q.push(tmp);
  63. }
  64. fish[] += time;
  65. if (sum > ans)
  66. {
  67. ans = sum;
  68. memcpy(res, fish, sizeof(fish));
  69. }
  70. }
  71. if (first) first = false;
  72. else printf("\n");
  73. for (int i = ; i < n; i++)
  74. printf("%d%s", res[i]*, (i==n-) ? "\n" : ", ");
  75. printf("Number of fish expected: %d\n", ans);
  76. }
  77. return ;
  78. }

UVa 757 - Gone Fishing的更多相关文章

  1. uva 757

    贪心  优先队列 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  2. <算法竞赛入门经典> 第8章 贪心+递归+分治总结

    虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...

  3. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  4. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  5. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. Jquery获取input=text 的值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. js选择一个选项 跳出另一个选项 跳出一个输入框

    跳出输入框 <script language="javascript"> function $(obj){return document.getElementById( ...

  3. Quartz总结(三):动态修改定时器一

    package com.mc.bsframe.job; import org.quartz.Scheduler; import org.quartz.SchedulerException; impor ...

  4. Allegro PCB -如何做自定义焊盘

    1.如何创建自定义焊盘,比如这种形状的焊盘. (1).打开PCB Editor –>Allegro PCB Design ->New,在类型中选择Shape symbol,并输入名字,比如 ...

  5. CodeForces 614A Link/Cut Tree

    #include<cstdio> #include<cstring> #include<cmath> #include<stack> #include& ...

  6. acm--统计错误数

    题目描述 题目地址:http://www.nowcoder.com/practice/67df1d7889cf4c529576383c2e647c48?tpId=49&tqId=29276&a ...

  7. 在MAC下配置MySQL 5.7 数据库的编码问题

    1.MySQL 5.7 for MAC 默认没有my.cnf文件 ,首先 新建my.cnf文件: 2.在my.cnf文件追加 [mysqld] character-set-server=utf8mb4 ...

  8. webservice中采用协议Http,它是指什么意思

    webservice 协议 Web Service使用的是 SOAP (Simple Object Access Protocol)协议soap协议只是用来封装消息用的.封装后的消息你可以通过各种已有 ...

  9. C程序编译执行过程

    C程序编译执行过程   认识C编译执行过程,是C学习的开端. 简单说C语言从编码编译到执行要经历一下过程:   C源代码 编译---->形成目标代码,目标代码是在目标机器上运行的代码. 连接-- ...

  10. hadoop hdfs uri详解

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...