uva 6757 Cup of Cowards(中途相遇法,貌似)
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


view code#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define iform "%I64d"
const int N = (1<<20)+10;
const ll INF = 1LL<<60;
ll _, L;
ll Min[N<<4],pos[N<<4], x[N<<1], xcnt;
ll d[100], c[100], cnt;
ll damage, cost;
struct node
{
ll v, c;
bool operator < (const node &o) const{
return v>o.v;
}
}one[N], two[N];
bool cmp(const node& a, const node &b)
{
return a.c<b.c;
}
void calc(node o[], int n, ll d[], ll c[], int &cnt)
{
cnt = 0;
for(int i=0; i<n; i++)
{
int k = cnt;
for(int j=0; j<k; j++)
{
if(o[j].v>=L) continue;
o[cnt].v = o[j].v+d[i];
o[cnt].c = o[j].c+c[i];
if(o[cnt].v>=L)
{
if(o[cnt].c<cost) cost = o[cnt].c, damage=o[cnt].v, cnt++;
else if(o[cnt].c==cost && damage>o[cnt].v) damage = o[cnt].v,cnt++;
}
else cnt++;
}
o[cnt].v = d[i];
o[cnt].c = c[i];
if(o[cnt].v>=L)
{
if(o[cnt].c<cost) cost = o[cnt].c, damage=o[cnt].v, cnt++;
else if(o[cnt].c==cost && damage>o[cnt].v) damage = o[cnt].v,cnt++;
}
else cnt++;
}
}
int ocnt, tcnt; void solve()
{
scanf(iform, &L);
ll num, dam, cos;
cnt = 0;
for(int i=1; i<=5; i++)
{
scanf(iform iform iform, &num, &dam, &cos);
ll k = 1;
while(num)
{
ll t = min(k, num);
d[cnt] = dam*t;
c[cnt] = cos*t;
cnt++;
num -= t;
k *= 2;
}
}
xcnt = 0;damage = -1, cost = INF;
ll n =cnt/2, m = cnt-n;
calc(one, n, d, c, ocnt);
calc(two, m, d+n, c+n, tcnt);
sort(one, one+ocnt, cmp);
sort(two, two+tcnt);
int i=0, j=0;
while(j<tcnt && two[j].v>=L) j++;
for(; i<ocnt&&j<tcnt; i++)
{
if(one[i].v>=L) continue;
else
{
while(j<tcnt && one[i].v+two[j].v>=L)
{
ll sumc = one[i].c+two[j].c;
ll sumv = one[i].v+two[j].v;
if(sumc<cost) damage=sumv,cost=sumc;
else if(sumc==cost) damage=sumv;
j++;
}
}
}
if(damage==-1) puts("We are doomed!!");
else cout<<cost<<""<<damage<<endl;
}
int main()
{
// freopen("in.txt", "r", stdin);
cin>>_;
while(_--) solve();
return 0;
}
uva 6757 Cup of Cowards(中途相遇法,貌似)的更多相关文章
- 紫书 例题8-3 UVa 1152(中途相遇法)
这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...
- 紫书 习题 8-16 UVa 1618 (中途相遇法)
暴力n的四次方, 然而可以用中途相遇法的思想, 分左边两个数和右边两个数来判断, 最后合起来判断. 一边是n平方logn, 合起来是n平方logn(枚举n平方, 二分logn) (1)两种比较方式是相 ...
- 【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) 解法:首先我们从最直接最暴力的方法开始思考:四重循 ...
- LA 2965 Jurassic Remains (中途相遇法)
Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 高效算法——J 中途相遇法,求和
---恢复内容开始--- J - 中途相遇法 Time Limit:9000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- 【UVALive】2965 Jurassic Remains(中途相遇法)
题目 传送门:QWQ 分析 太喵了~~~~~ 还有中途相遇法这种东西的. 嗯 以后可以优化一些暴力 详情左转蓝书P58 (但可能我OI生涯中都遇不到正解是这个的题把...... 代码 #include ...
- uva1152 - 4 Values whose Sum is 0(枚举,中途相遇法)
用中途相遇法的思想来解题.分别枚举两边,和直接暴力枚举四个数组比可以降低时间复杂度. 这里用到一个很实用的技巧: 求长度为n的有序数组a中的数k的个数num? num=upper_bound(a,a+ ...
随机推荐
- GJM : 进程、线程和协程的理解
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- JQuery读取XML文件
<?xml version="1.0" encoding="utf-8" ?> <taxrates> <taxrate id=&q ...
- OriDomi – 像折叠纸张一样折叠 DOM 元素
Web 原本是扁平化的,但是现在你可以折起来.OriDomi 是一个开源的 JavaScript 库,使得 DOM 元素能够实现像纸折一样折叠的效果.在创建你所看到的场景背后,OriDomi 做了大量 ...
- 12款免费的 WordPress 响应式主题下载
最流行的内容管理系统(WordPress)和最流行的网页设计技术(响应式设计)结合会是什么样的呢?下面这个列表收集了12款响应式的 Wordpress 主题,能够带给你不一样的网站体验. 您可能感兴趣 ...
- 学习 Mobile App 网站制作的11个优秀案例
我喜欢收集美丽的,精心设计的移动应用程序网站.在我看来,为 App 提供一个美丽的网站显示了设计者和开发者对它的用户和产品的关心,除了开发应用程序,他们去加倍努力去促进应用和传播关于它的 App. 我 ...
- 经典网页设计:20个华丽的 iPhone 应用程序演示网站
一个物品销售很好,重要的原因之一是它的包装,因为这是最重要的细节,可以把一个人转变成购买者.一个好的包装设计和良好的表现比产品本身更重要,因此被分配了大量的金钱和资源,以创造伟大的东西. 因此,为了销 ...
- Subway Icon Set – 306个像素完美的特制图标
这个图标集是306个优化的像素完美,精雕细琢的图标.为这些设备进行了优化:iOS.Windows Phone.Windows 8 and BlackBerry 10,提供 PNG, SVG, XALM ...
- Kafka主要参数详解(转)
原文档地址:http://kafka.apache.org/documentation.html ############################# System ############## ...
- Python学习01 Hello World
Python学习之Hello World 准备工作 去官网http://www.python.org/ 下载python的安装包: http://www.python.org/download/ 当前 ...
- 怎么让一个项目里swift与OC可以兼容混合开发?
在苹果推出了swift语言之后,很多人担心OC很快会被取代,但是苹果方面表示2年内不会摒弃OC.但现在也快了啊.有的开发团队已经开始基于swift开发,但是有很多旧的框架还没来得及用swift写出来, ...