2018CCPC吉林赛区(重现赛)- 1009 The Hermit

Problem Description

Strength gives you the confidence within yourself to overcome any fears, challenges or doubts. Feel the fear and do it anyway! If you have been going through a rough time and feel burnt out or stressed, the Strength card encourages you to find the strength within yourself and keep going. You have got what it takes to see this situation through to its eventual end. You might also feel compelled to hold space for someone else who is going through a difficult period and needs your strength and support.

Alice and Bob are playing “Yu-Gi-Oh!”, a famous turn-based trading card game, in which two players perform their turns alternatively. After several turns, Alice and Bob have many monsters respectively.
Alice has n and Bob has m monsters under their own control. Each monster’s strength is measured by a non-negative integer si . To be specific, the larger si is, the more power the monster has.
During each turn, for every single monster under control, the player can give a command to it at most once, driving it to battle with an enemy monster (given that opposite player has no monsters as a shield, the monster can directly attack him).
Additionally, the process of the battle is also quite simple. When two monsters battle with each other, the stronger one (i.e. the one with larger si ) will overwhelm the other and destroy it and the winner’s strength will remain unchanged. Meanwhile, the difference of their strength will produce equivalent damage to the player who loses the battle. If the player is directly attacked by a monster, he will suffer from the damage equal to the monster’s strength. Notice that when two monsters have the same strength, both of them will vanish and no damage will be dealt.
Right now it is Alice’s turn to play, having known the strength of all monsters, she wants to calculate the maximal damage she can deal towards Bob in one turn. Unfortunately, Bob has great foresight and is well-prepared for the upcoming attack. Bob has converted several of his monsters into defense position,
in which even if the monster is destroyed, he wouldn’t get any damage.
Now you are informed of the strength of all the monsters and whether it is in defense position for each Bob’s monster, you are expected to figure out the maximal damage that could be dealt in this turn.

Input

The first line contains a single integer T ≤ 20 indicating the number of test cases.
For each test case, the first line includes two integer 0 ≤ n , m ≤ 100000, representing the number of monsters owned by Alice and Bob.
In next three lines, the first two lines include n and m integers 0 ≤ si ≤ 109 indicating the strength of the i -th monster, separated by spaces. The last line contains m integers 0 or 1 indicating the position of Bob’s i -th monsters.In other words, 0 represents the normal position and 1 represents the defense position.

Output

For the ith test, output a single line in beginning of “Case i :”, followed by an integer indicating the answer, separated by a single space.

Sample Input

2 
4 2 
10 10 10 20 
5 15 
0 1 
4 2 
10 10 10 20 
5 25 
0 1
Sample Output
Case 1: 25 
Case 2: 15

【题解】

队友A的 据说是游戏王 先判断能不能全部杀死 能的话就用攻击接近防御的打防御 然后其他打脸 不能全部杀死的 就用最高攻打他最小攻击 贪就完事了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int T,cas=1;
    int a[100005],b[100005],gon[100005],fan[100005],f;
    int vis[100005];
    scanf("%d",&T);
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        int xg=0,xf=0;
        int n,m;
        scanf("%d %d",&n,&m);
        for(int i=0; i<n; i++)
            cin>>a[i];
        for(int i=0; i<m; i++)
            cin>>b[i];
        for(int i=0; i<m; i++)
        {
            cin>>f;
            if(f)
                fan[xf++]=b[i];
            else
                gon[xg++]=b[i];
        }
        sort(a,a+n,cmp);
        sort(gon,gon+xg);
        sort(fan,fan+xf,cmp);
        int ans=-1,agon,bfan,bgon,sum;
        agon=n-1;
        bfan=xf-1;
        while(agon>=0&&bfan>=0)
        {
            if(a[agon]>=fan[bfan])
            {
                vis[agon]=1;
                agon--;
                bfan--;
            }
            else
            {
                agon--;
            }
        }
        if(bfan==-1)
        {
            agon=0;
            bgon=xg-1;
            sum=0;
            while(agon<n&&bgon>=0)
            {
                if(vis[agon])
                {
                    agon++;
                    continue;
                }
                if(a[agon]>=gon[bgon])
                {
                    sum+=a[agon]-gon[bgon];
                    agon++;
                    bgon--;
                }
                else
                    break;
            }
            if(bgon==-1)
            {
                while(agon<n)
                {
                    if(vis[agon])
                    {
                        agon++;
                        continue;
                    }
                    sum+=a[agon];
                    agon++;
                }
                ans=max(ans,sum);
            }

        }
        sum=0;
        agon=0,bgon=0,bfan=xf-1;

        while(agon<n&&bgon<xg)
        {
            if(a[agon] >= gon[bgon])
            {
                sum+=a[agon]-gon[bgon];
                agon++;
                bgon++;
            }
            else
                break;
        }
        int abs=0;
        if(bgon != xg)
        {
            ans = max(ans, sum);
        }
        else
        {
            int i=n-1;
            while(i>=agon&&bfan>=0)
            {
                if(a[i]>=fan[bfan])
                {
                    i--;
                    bfan--;
                }
                else
                {
                    abs+=a[i];
                    i--;
                }
            }
            if(bfan==-1)
            {
                sum+=abs;
                if(i!=agon)
                {
                    while(i>=agon)
                    {
                        sum+=a[i];
                        i--;
                    }
                }
            }
            ans = max(ans,sum);
        }
          printf("Case %d: %d\n",cas++,ans);
    }
    return 0;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值