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+ ...
随机推荐
- 详解spring 每个jar的作用
spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...
- java web学习总结(一) -------------------基本概念
一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...
- angular学习的一些小笔记(中)之ng-disabled轻松实现按钮是否可点击状态
哇,这个可以轻松实现输入值就按钮可点击,输入框没有值则不可点击的状态呀 看代码 <!doctype html> <html ng-app=""> <h ...
- 20款免费响应式的 HTML5 网站模板下载
今天这篇文章给大家带来的是20款免费响应式的 HTML5 网站模板,大家可以借助这些优秀的网站模板创建自己的优秀网站.响应式(Responsive Design)设计的目标是要让产品界面能够响应用户的 ...
- emberjs学习一(环境和第一个例子)
code { margin: 0; padding: 0; white-space: pre; border: none; background: transparent; } code, pre t ...
- MongoDB,客户端工具备份数据库
本篇介绍下如何利用客户端工具来进行远程服务器的数据备份到本地. 以客户端工具MongoVUE为例来进行讲解: 1.首先要连接本地服务器以及远程服务器数据库 2.在本地服务器(127.0.0.1)中,右 ...
- SharePoint Online 创建门户网站系列之准备篇
前 言 门户是SharePoint自推出以来,就非常适合的一种站点类型,在Server版本中,发布站点的应用非常广泛.这里,我们以一个个简单的例子,然后以一个固定的项目Demo,为大家演示如何一步步在 ...
- Android HTTP实例 使用GET方法和POST方法发送请求
Android HTTP实例 使用GET方法和POST方法发送请求 Web程序:使用GET和POST方法发送请求 首先利用MyEclispe+Tomcat写好一个Web程序,实现的功能就是提交用户信息 ...
- RapidFloatingActionButton框架正式出炉
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4474748.html RapidFloatingActionB ...
- git 上的pull request 是什么意思?
1.git 上有常见的pull request 功能 2.pull request 的含义 解释一: 有一个仓库,叫Repo A.你如果要往里贡献代码,首先要Fork这个Repo,于是在你的Gi ...