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;
}

转载于:https://www.cnblogs.com/zyx1314/p/3928077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值