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+ ...
随机推荐
- Discuz X2任务开发
简单描述 由于公司的需求要在系统中添加任务管理,用户通过完成任务而获得一定的奖励,因此其设计过程需要考虑到: 1.由于任务都是在系统中相关功能块处做一些相关事情,比如说在做题系统中完成指定的试题[1] ...
- Spring4学习笔记2-配置集合属性
1 可使用<list> <map> <set>等来配置集合属性 2 List <!-- 配置List属性 --> <bean id="p ...
- Perfect Scrollbar – 完美的 jQuery 滚动条插件
Perfect Scrollbar 是一个很小的,但完美的 jQuery 滚动插件.滚动条不会影响原来的设计布局,滚动条的设计是完全可定制的.你可以改变几乎所有的 CSS 样式的滚动条,滚动条设计对脚 ...
- Croppic – 免费开源的 jQuery 图片裁剪插件
Croppic 这款开源的 jQuery 图片裁剪插件能够满足网站开发人员各种不同的使用需要.只需要简单的上传图片,就可以实现你想要的图像缩放和裁剪功能.因为使用了 HTML5 FormData 对 ...
- Julius JS – 最流行的网页语音识别库
JuliusJS 是用于在网页中的语音识别库.这是 Julius(由日本京都大学和日本IPA联合开发的一个实用高效双通道的大词汇连续语音识别引擎)的 JavaScript 实现.它实时侦听用户的语音并 ...
- BP人工神经网络原理(转载)
- .net 模拟登录Post提交
最近在做一个项目,要求集成到第三方系统中,由于先前没有做过类似的活,所以折腾了几天,蹭着有闲情的时候记录一下. 以下实例,都是我用Asp.net语言进行开发的,关于HTML元素的获取,使用的是Goog ...
- 关于AutoCAD 2014的securityload…
昨天一个朋友给我打电话提到他关于AutoCAD 2014中安全加载SECURTY LOAD的一些困惑,我的同事Fenton写了一篇博客,对AutoCAD 2014安全加载的来龙去脉做了深入详细的阐述, ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q52-Q55)
Question 52You are responsible for rebranding the My Sites section of a corporate SharePoint 2010 fa ...
- IOS常用第三方开源类库&组件
1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功能强大, 现在许多人 ...