uva 6757 Cup of Cowards
Cup of Cowards (CoC) is a role playing game that has 5 different characters (Mage, Tank, Fighter,
Assassin and Marksman). A team consists of 5 players (one from each kind) and the goal is to kill a
monster with L life points. The monster dies if the total damage it gets is at least L. Each character
has a certain number of allowed hits, each hit has a certain damage and a certain cost (the cost and
damage might be different for each character). The team wants to kill the monster using the minimum
cost so they can perform better in later missions. They want your help to find the minimum cost they
will pay to kill the monster and the damage they should incur on it.
Input
Your program will be tested on one or more test cases. The first line of the input will be a single
integer T, the number of test cases (1 ≤ T ≤ 100). Followed by the test cases, the first line of each
test case contains 1 integer L (0 ≤ L ≤ 1012) representing the life points of the monster. Followed by
5 lines, each one contains 3 integers separated by a single space H D C representing the maximum
number of hits, the damage by each hit and the cost of each hit by one of the characters, respectively
(0 ≤ H ≤ 1, 000), (0 ≤ D, C ≤ 109
) and the sum of the maximum number of hits for all characters will
not be more than 1,000.
Output
For each test case, print a single line which contains 2 space separated integers, the first is the minimum
cost for the hits used to kill the monster and the second is the damage incurred upon the monster. If
there is more than one way to kill the monster using the same minimum cost, select the one with the
least damage and if there is no way to kill the monster print ‘We are doomed!!’ (without the quotes).
Sample Input
2
33
2 3 4
3 1 2
4 3 2
1 7 1
3 4 2
51
3 3 1
4 3 2
2 3 3
3 1 4
5 2 3
Sample Output
19 33
We are doomed!!

貌似中途相遇法,时间2500ms

  1. view code#include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cstdio>
  5. using namespace std;
  6. typedef long long ll;
  7. #define lson l,m,rt<<1
  8. #define rson m+1,r,rt<<1|1
  9. #define iform "%I64d"
  10. const int N = (1<<20)+10;
  11. const ll INF = 1LL<<60;
  12. ll _, L;
  13. ll Min[N<<4],pos[N<<4], x[N<<1], xcnt;
  14. ll d[100], c[100], cnt;
  15. ll damage, cost;
  16. struct node
  17. {
  18. ll v, c;
  19. bool operator < (const node &o) const{
  20. return v>o.v;
  21. }
  22. }one[N], two[N];
  23. bool cmp(const node& a, const node &b)
  24. {
  25. return a.c<b.c;
  26. }
  27. void calc(node o[], int n, ll d[], ll c[], int &cnt)
  28. {
  29. cnt = 0;
  30. for(int i=0; i<n; i++)
  31. {
  32. int k = cnt;
  33. for(int j=0; j<k; j++)
  34. {
  35. if(o[j].v>=L) continue;
  36. o[cnt].v = o[j].v+d[i];
  37. o[cnt].c = o[j].c+c[i];
  38. if(o[cnt].v>=L)
  39. {
  40. if(o[cnt].c<cost) cost = o[cnt].c, damage=o[cnt].v, cnt++;
  41. else if(o[cnt].c==cost && damage>o[cnt].v) damage = o[cnt].v,cnt++;
  42. }
  43. else cnt++;
  44. }
  45. o[cnt].v = d[i];
  46. o[cnt].c = c[i];
  47. if(o[cnt].v>=L)
  48. {
  49. if(o[cnt].c<cost) cost = o[cnt].c, damage=o[cnt].v, cnt++;
  50. else if(o[cnt].c==cost && damage>o[cnt].v) damage = o[cnt].v,cnt++;
  51. }
  52. else cnt++;
  53. }
  54. }
  55. int ocnt, tcnt;
  56.  
  57. void solve()
  58. {
  59. scanf(iform, &L);
  60. ll num, dam, cos;
  61. cnt = 0;
  62. for(int i=1; i<=5; i++)
  63. {
  64. scanf(iform iform iform, &num, &dam, &cos);
  65. ll k = 1;
  66. while(num)
  67. {
  68. ll t = min(k, num);
  69. d[cnt] = dam*t;
  70. c[cnt] = cos*t;
  71. cnt++;
  72. num -= t;
  73. k *= 2;
  74. }
  75. }
  76. xcnt = 0;damage = -1, cost = INF;
  77. ll n =cnt/2, m = cnt-n;
  78. calc(one, n, d, c, ocnt);
  79. calc(two, m, d+n, c+n, tcnt);
  80. sort(one, one+ocnt, cmp);
  81. sort(two, two+tcnt);
  82. int i=0, j=0;
  83. while(j<tcnt && two[j].v>=L) j++;
  84. for(; i<ocnt&&j<tcnt; i++)
  85. {
  86. if(one[i].v>=L) continue;
  87. else
  88. {
  89. while(j<tcnt && one[i].v+two[j].v>=L)
  90. {
  91. ll sumc = one[i].c+two[j].c;
  92. ll sumv = one[i].v+two[j].v;
  93. if(sumc<cost) damage=sumv,cost=sumc;
  94. else if(sumc==cost) damage=sumv;
  95. j++;
  96. }
  97. }
  98. }
  99. if(damage==-1) puts("We are doomed!!");
  100. else cout<<cost<<""<<damage<<endl;
  101. }
  102. int main()
  103. {
  104. // freopen("in.txt", "r", stdin);
  105. cin>>_;
  106. while(_--) solve();
  107. return 0;
  108. }

uva 6757 Cup of Cowards(中途相遇法,貌似)的更多相关文章

  1. 紫书 例题8-3 UVa 1152(中途相遇法)

    这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...

  2. 紫书 习题 8-16 UVa 1618 (中途相遇法)

    暴力n的四次方, 然而可以用中途相遇法的思想, 分左边两个数和右边两个数来判断, 最后合起来判断. 一边是n平方logn, 合起来是n平方logn(枚举n平方, 二分logn) (1)两种比较方式是相 ...

  3. 【uva 1152】4 Values Whose Sum is Zero(算法效率--中途相遇法+Hash或STL库)

    题意:给定4个N元素几个A,B,C,D,要求分别从中选取一个元素a,b,c,d使得a+b+c+d=0.问有多少种选法.(N≤4000,D≤2^28) 解法:首先我们从最直接最暴力的方法开始思考:四重循 ...

  4. LA 2965 Jurassic Remains (中途相遇法)

    Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...

  5. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  6. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. 高效算法——J 中途相遇法,求和

    ---恢复内容开始--- J - 中途相遇法 Time Limit:9000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...

  8. 【UVALive】2965 Jurassic Remains(中途相遇法)

    题目 传送门:QWQ 分析 太喵了~~~~~ 还有中途相遇法这种东西的. 嗯 以后可以优化一些暴力 详情左转蓝书P58 (但可能我OI生涯中都遇不到正解是这个的题把...... 代码 #include ...

  9. uva1152 - 4 Values whose Sum is 0(枚举,中途相遇法)

    用中途相遇法的思想来解题.分别枚举两边,和直接暴力枚举四个数组比可以降低时间复杂度. 这里用到一个很实用的技巧: 求长度为n的有序数组a中的数k的个数num? num=upper_bound(a,a+ ...

随机推荐

  1. [小北De编程手记] : Lesson 05 玩转 xUnit.Net 之 从Assert谈UT框架实践

    这一篇,本文会介绍一下基本的断言概念,但重点会放在企业级单元测试的相关功能上面.下面来跟大家分享一下xUnit.Net的断言,主要涉及到以下内容: 关于断言的概念 xUnit.Net常用的断言 关于单 ...

  2. svn利用钩子实现代码同步到web目录

    思路:  找 到SVN Server中的仓库(Repositories)文件夹的位置,在相应的项目文件夹中找到hooks文件夹.在该文件夹中添加一个post- commit文件:当有commit动作发 ...

  3. 一个完整的类用来读取OpenSSL生成的pem格式的x509证书

    internal static class CcbRsaHelper { private const string Begin = "-----BEGIN "; private c ...

  4. 对于 Web 开发很有用的 jQuery 效果制作教程

    如果你的项目中需要响应式滑块,炫丽的图片呈现,对话框提示,轻巧动画等效果,jQuery 是完美的解决方案.凭借这个快速,易用的 JavaScript 库,可以轻松处理语言之间的交互,它给人最快速的 W ...

  5. Web 开发中应用 HTML5 技术的10个实例教程

    HTML5 作为下一代网站开发技术,无论你是一个 Web 开发人员或者想探索新的平台的游戏开发者,都值得去研究.借助尖端功能,技术和 API,HTML5 允许你创建响应性.创新性.互动性以及令人惊叹的 ...

  6. 如何在SharePoint2010中创建自定义电子邮件警报处理程序

    字段,如项目名称字段中,将被截断到的电子邮件通知中的 70 个字符.要解决 70 个字符的限制,请使用"更多信息"一节中的介绍的方法. 要嵌入电子邮件通知中的其他内容. 您想要更改 ...

  7. Java学习心得之 Linux下搭建JavaWeb环境

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Java学习心得之 Linux下搭建JavaWeb环境 1. 前言2. Java安装3. t ...

  8. Xcode中XVim的常用操作

  9. xmpp整理笔记:环境的快速配置(附安装包)

    现在虽然环信的xmpp框架很火,但是也有一些弊端.环信的框架部分代码不开源,而且收费模式不科学,用户量一直低于免费线则好,一旦超过,收费极高. xmpp感觉还是从xmppFramework框架学起比较 ...

  10. 禁止uiscrollview垂直方向滚动,只允许水平方向滚动;或只允许垂直方向滚动

    禁止UIScrollView垂直方向滚动,只允许水平方向滚动 scrollview.contentSize =  CGSizeMake(你要的长度, 0); 禁止UIScrollView水平方向滚动, ...