STRENGTH

题目链接

题目描述

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.

输入

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 O≤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 O≤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’Si-th monsters. In other words, 0 represents the normal position and 1 represents the defense position.

输出

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.

样例输入

2
4 2
10 10 10 20
5 15
0 1
4 2
10 10 10 20
5 25
0 1

样例输出

Case 1: 25
Case 2: 15

题意

玩游戏王牌,我方场上n只怪兽,都是攻击形态,战斗力为a[i];

敌方m只怪兽,战斗力为b[i],如果下一行是0表示攻击形态,1表示防御形态

如果我方怪兽的战斗力攻击对方攻击形态的怪兽,就会消灭对方的怪兽,并造成超杀(对敌人本体造成战斗力的差值a[i] - b[i]的血量),如果攻击防御形态的怪兽兽,则会消灭怪兽而不会扣对方本体的血量

如果敌人没有怪兽了,就可以对敌人本体造成直接伤害a[i];

每只怪兽只能攻击一次

问怎么才能扣敌人最多的血

题解

有两种贪心策略

一种是 直接拿战斗力高的去怼敌人战斗力低的攻击形态怪,这样造成的超杀值高

第二种 用战斗力高的去消灭所有的防御怪和攻击怪,然后直接对本体进行攻击

分别求出两种贪心策略的结果求max

代码写的相当繁琐

代码

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define scac(x) scanf("%c",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ll long long
#define LL long long
#define read read()
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define N 205
const int maxn = 1e5+5;
ll a[maxn],b[maxn];
ll g[maxn];//gong
ll s[maxn];//shou
int vis[maxn];
int op;
bool cmp(ll x,ll y)
{
return x > y;
}
int main()
{
int t;
sca(t);
int kase = 0;
while(t--)
{
memset(vis,0,sizeof(vis));
int n,m;
sca2(n,m);
rep(i,0,n) scl(a[i]);
rep(i,0,m) scl(b[i]);
int cntg = 0;
int cnts = 0;
rep(i,0,m)
{
sca(op);
if(op) s[cnts++] = b[i];
else g[cntg++] = b[i];
}
sort(a,a+n,cmp); // da -> xiao
sort(g,g+cntg); // xiao -> da
sort(s,s+cnts,cmp); // da -> xiao
int posa = 0;
int posg = 0;
int poss = cnts-1;
ll ans = -1;
ll temp = 0;
while(posa < n && posg < cntg) //plan1 先打攻击怪
{
if(a[posa] >= g[posg])
{
temp += a[posa] - g[posg];
posa++;
posg++;
}
else
break;
}
ll sum = 0;
if(posg != cntg) //我方怪打完了,对方攻击怪还有剩余
{
ans = max(ans, temp);
}
else
{
int i = n-1;
while(i >= posa && poss >= 0)//开始打防守怪
{
if(a[i] >= s[poss])
{
i--;
poss--;
}
else
{
sum += a[i];
i--;
}
}
if(poss == -1)
{
temp += sum;
if(i != posa)
{
while(i>=posa)
{
temp += a[i];
i--;
}
}
}
ans = max(ans,temp);
} posa = n-1;
poss = cnts - 1;
while(posa >= 0 && poss >= 0) //plan2 先打防守怪
{
if(a[posa] >= s[poss])
{
vis[posa] = 1;
posa--;
poss--;
}
else
{
posa--;
}
}
if(poss == -1)
{
posa = 0;
posg = cntg - 1;
temp = 0;
while(posa < n && posg >= 0)
{
if(vis[posa]) //前面拿来打防守怪了
{
posa++;
continue;
}
if(a[posa] >= g[posg])
{
temp += a[posa] - g[posg];
posa++;
posg--;
}
else
{
break;
}
}
if(posg == -1)
{
while(posa < n)
{
if(vis[posa])
{
posa++;
continue;
}
temp += a[posa];
posa++;
}
ans = max(ans,temp);
}
} printf("Case %d: %lld\n",++kase,ans);
}
return 0; }

upc 组队赛18 STRENGTH【贪心模拟】的更多相关文章

  1. upc组队赛18 THE WORLD【时间模拟】

    THE WORLD 题目链接 题目描述 The World can indicate world travel, particularly on a large scale. You mau be l ...

  2. upc组队赛16 WTMGB【模拟】

    WTMGB 题目链接 题目描述 YellowStar is very happy that the FZU Code Carnival is about to begin except that he ...

  3. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  4. 贪心+模拟 ZOJ 3829 Known Notation

    题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...

  5. CodeForces ---596B--Wilbur and Array(贪心模拟)

    Wilbur and Array Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Su ...

  6. 18/9/22NOIP模拟考

    18/9/22NOIP模拟考 其实本来是有多组数据的,出题人忘记在题面上加了   斜眼笑 期望得分:100:实际得分:100 由于种种原因,拿到题的时候已经过去了0.5h+... 然后因为这道题数据范 ...

  7. 18/9/21模拟赛-Updated

    18/9/21模拟赛 期望得分:100:实际得分:0  qwq 拿到题目第一眼,我去,这不是洛谷原题(仓鼠找Sugar)吗 又多看了几眼,嗯,对,除了是有多组数据外,就是原题 然后码码码....自以为 ...

  8. upc组队赛15 Lattice's basics in digital electronics【模拟】

    Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...

  9. upc组队赛6 Progressive Scramble【模拟】

    Progressive Scramble 题目描述 You are a member of a naive spy agency. For secure communication,members o ...

随机推荐

  1. [HNOI2016]树(可持久化线段树+树上倍增)

    [HNOI2016]树(可持久化线段树+树上倍增) 题面 给出一棵n个点的模板树和大树,根为1,初始的时候大树和模板树相同.接下来操作m次,每次从模板树里取出一棵子树,把它作为新树里节点y的儿子.操作 ...

  2. 靶形数独 (dfs+预处理+状态压缩)

    #2591. 「NOIP2009」靶形数独 [题目描述] 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们 ...

  3. 给当当同学的random data

    m**o 00'57"32街**o 00'52"23c**6 00'44"15斗**6 00'57"58n**5 00'32"04s**p 00'51 ...

  4. centos7.4安装mysql

    yum -y install mysql mysql-server mysql-devel mysql-server报错:No package mysql-server available,另外两个没 ...

  5. devops持续集成,Centos7.6下gitlab+jenkins(pipeline)实现代码自动上线

    持续集成 gitlab+jenkins(pipeline)实现代码自动上线 环境准备:Centos7.6版本ip:192.168.0.13 主机名:gitip:192.168.0.23 主机名:jen ...

  6. 输vim /etc/rc.d/init.d/mysqld 报错 …..localdomain.pid

    在安装MySQL的过程中出现以下错误: 本人解决方法是: ps aux | grep mysqld 罗列出所有关于mysqld的进程,然后把关于mysqld的进程都kill了.

  7. springboot+UEditor图片上传

    springboot+UEDitor百度编辑器整合图片上记录于此 1.下载ueditor插件包,解压到static/ueditor目录下 2.在你所需实现编辑器的页面引用三个JS文件 1)  uedi ...

  8. j函数 判断以 什么开头

    1.str.charAt(index) 返回字符串中指定位置的字符. str 是字符串  我们要将获得的数据 转化为字符串 var code = res.statusCode.toString(); ...

  9. windows cmd bat处理文件

    bat中输入: @echo offtitle 正在承载无线网络....netsh wlan start hostednetworknetsh wlan show hostednetworkecho 启 ...

  10. 【leetcode】816. Ambiguous Coordinates

    题目如下: 解题思路:我的方案是先把S拆分成整数对,例如S='1230',先拆分成(1,230),(12,30),(123,0),然后再对前面整数对进行加小数点处理.比如(12,30)中的12可以加上 ...