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(中途相遇法,貌似)的更多相关文章

  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. Jmeter常用函数之__CSVRead使用

    __CSVRead函数用于对脚本进行参数话,当脚本中不同变量需要不同参数值时,可以考虑__CSVRead函数. 以登录的用户名.密码为例:实际进行压力测试时,需要模拟使用不同的用户并发访问系统,此时需 ...

  2. java多线程-线程通信

    线程通信的目标是使线程间能够互相发送信号.另一方面,线程通信使线程能够等待其他线程的信号. 通过共享对象通信 忙等待 wait(),notify()和 notifyAll() 丢失的信号 假唤醒 多线 ...

  3. Struts2详细教程

    Struts2详细教程:http://www.yiibai.com/struts_2/

  4. 原型prototype

    JS对象的比较 由于JS是解释执行的语言,那么代码中出现函数与对象如果重复执行,会创建多个副本 创建一个Person构造函数,要求有name,age,gender,sayHello 代码如下: fun ...

  5. 使用js实现带有停顿效果的图片滚动(按钮控制)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. SharePoint Server 2016 Update

    Today’s post was written by Seth Patton, senior director of product management for the SharePoint te ...

  7. [android]AndroidInject框架——我的第一个android小型框架

    作为一个移动应用开发者,随着需求的日益增多,Android项目的越来越臃肿,代码量越来越大, 现在冷静下来回头看看我们的代码,有多少代码跟业务逻辑没什么关系的 所以,本人自不量力,在github上建了 ...

  8. spring理解

    Struts与Hibernate可以做什么事? Struts,Mvc中控制层解决方案,可以进行请求数据自动封装.类型转换.文件上传.效验… Hibernate,持久层的解决方案:可以做到,把对象保存到 ...

  9. sqlite API模型

     每一个数据库连接可以包括多个数据库文件,一个主数据库文件和attached的几个数据库文件. 每一个数据库文件都有自己的B-tree和pager. 数据库连接(connection)和事务(tra ...

  10. JAVA Web 实现会话跟踪的技术笔记

    1.HTTP协议无状态:客户端的请求与服务器的响应所发生的一系列行为简单的说是客户发送了请求,服务器就给客户端响应,它们彼此之间都没有记录下来.如: 顾客与自动售货机 普通顾客(非会员)与商场 2.c ...