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+ ...
随机推荐
- C#多线程:使用ReaderWriterLock类实现多用户读/单用户写同步
摘要:C#提供了System.Threading.ReaderWriterLock类以适应多用户读/单用户写的场景.该类可实现以下功能:如果资源未被写操作锁定,那么任何线程都可对该资源进行读操作锁定, ...
- (转载)Windows常见性能计数器(较好的说明)
转载地址:http://blog.csdn.net/dfbrt56/article/details/3341591 Windows常见性能计数器 性能计数器(counter)是描述服务器或操作系统性能 ...
- JavaScript中数组的增删改查
数组的增加 ary.push() 向数组末尾添加元素,返回的是添加后新数组的长度,原有数组改变 ary.uns ...
- 浅谈float浮动
float大概是css3以前网页布局里最常用的一个属性了,经常看到一言不合就浮动的代码,就一起来深入挖掘一下这个一半天使一半魔鬼的属性吧. 本文是读张鑫旭大神慕课网float视频后的一些总结及一些拓展 ...
- sharepoint2013的最少下载策略概述(MDS)
该策略是 SharePoint 2013 中的一种新功能,通过在用户导航到新页面时仅发送差异内容来减少页面加载时间. 最少下载策略 (MDS) 是 SharePoint 2013 中的一种新技术,可减 ...
- 转-Nmap扫描原理与用法
1 Nmap介绍 操作系统与设备类型等信息. Nmap的优点: 1. 灵活.支持数十种不同的扫描方式,支持多种目标对象的扫描. 2. 强大.Nmap可以用于扫描互联网上大规 ...
- 操作系统开发系列—13.c.进程之中断重入
现在又出现了另外一个的问题,在中断处理过程中是否应该允许下一个中断发生? 让我们修改一下代码,以便让系统可以在时钟中断的处理过程中接受下一个时钟中断.这听起来不是个很好的主意,但是可以借此来做个试验. ...
- git 上的pull request 是什么意思?
1.git 上有常见的pull request 功能 2.pull request 的含义 解释一: 有一个仓库,叫Repo A.你如果要往里贡献代码,首先要Fork这个Repo,于是在你的Gi ...
- Android 隐式意图和显示意图的使用场景
本文实现一个隐式意图的应用,激活短信应用 public void click4(View view) { Intent intent = new Intent(); intent.setAction( ...
- iOS 设置系统屏幕亮度
// 设置系统屏幕亮度 // [UIScreen mainScreen].brightness = value; // 或者 [[UIScreen mainScreen] se ...