upc 组队赛18 STRENGTH【贪心模拟】

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 -> xiaosort(g,g+cntg); // xiao -> dasort(s,s+cnts,cmp); // da -> xiaoint 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++;}elsebreak;}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;}

转载于:https://www.cnblogs.com/llke/p/10822416.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275185.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JSONNull

最近用JSONObject&#xff0c;感觉比xml好用一些&#xff0c;json的打包和解包都比较清晰和容易&#xff0c;最近遇到一个问题&#xff0c;将一个JSON对象解析&#xff0c;存到hashmap中去&#xff0c;然后再从hashmap取出数据&#xff0c;遇到jsonnull的问题&#xff0c;本以为…

“这张图告诉你什么?”

For data to be impactful, it must be understood.为了使数据具有影响力&#xff0c;必须理解它。 I’ve happily spent hundreds and hundreds of hours of my life watching users misunderstand data visualizations. I’m strangely hooked on it.我快乐地度过了数百个小…

我们从 UmiJS 迁移到了 Vite

大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以点此加我微信ruochuan12 进群参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。已进行三个月了&#xff0c;很多小伙伴表示收获颇丰。我们从 UmiJS迁移到 Vite 已经上线半年…

将DataTable的内容以EXCEl的形式导出到本地

1.在搞项目的时候一般会遇到&#xff0c;将GridView或者Repeater的内容以Excel的形式保存到本地&#xff0c;即导出功能。我总结了两个方法。 方法一&#xff1a; 1 DataTable dt query.GetItems().GetDataTable();2 if (dt ! null)3 {4 …

智能家居数据库设计_设计更智能的数据表

智能家居数据库设计重点 (Top highlight)Data tables are hard. There are many different ways to think about them. So, naturally, the first step would be to figure out what your users need.数据表很难。 有许多不同的方式来考虑它们。 因此&#xff0c;自然地&#x…

可能是全网首个前端源码共读活动,诚邀你加入一起学习

大家好&#xff0c;我是若川。众所周知&#xff0c;从8月份开始&#xff0c;我组织了源码共读活动&#xff0c;每周学习200行左右的源码&#xff0c;到现在持续了3个多月&#xff0c;坚持答疑解惑。帮助了不少人&#xff0c;还是挺开心的。另外&#xff0c;涌现了很多优秀的读者…

vsftpd 的配置项目

基本配置说明&#xff1a; 1&#xff09;local_root/ftpfile(当本地用户登入时&#xff0c;将被更换到定义的目录下&#xff0c;默认值为各用户的家目录) 2&#xff09;anon_root/ftpfile(使用匿名登入时&#xff0c;所登入的目录) 3&#xff09;use_localtimeYES(默认是GMT时…

线段树专辑——pku 3667 Hotel

http://poj.org/problem?id3667 哈哈&#xff0c;经典中的经典题啊。利用线段树求最大连续空闲区间&#xff0c;并返回空闲区间的起点坐标。 View Code 1 #include<iostream> 2 #include<string> 3 #include<algorithm> 4 using namespace std; 5 6 …

houseparty不流畅_重新设计Houseparty –用户体验案例研究

houseparty不流畅Houseparty has become very popular during the COVID-19 period because it helps you connect with others in a fun way. The concept is simple, you open the app and jump on a video call with your friends. You can even play online games with the…

你不知道的 Node.js 工具函数

从类型判断说起在 JavaScript 中&#xff0c;进行变量的类型校验是一个非常令人头疼的事&#xff0c;如果只是简单的使用 typeof 会到各种各样的问题。举几个简单的&#x1f330;&#xff1a;console.log(typeof null) // object console.log(typeof new Array) // object cons…

Java应用集群下的定时任务处理方案(mysql)

今天来说一个Java多机部署下定时任务的处理方案。 需求: 有两台服务器同时部署了同一套代码&#xff0c; 代码中写有spring自带的定时任务&#xff0c;但是每次执行定时任务时只需要一台机器去执行。 当拿到这个需求时我脑子中立马出现了两个简单的解决方案&#xff1a; 利用ip…

概念验证_设置成功的UX概念验证

概念验证用户体验/概念证明/第1部分 (USER EXPERIENCE / PROOF OF CONCEPT / PART 1) This is the first article of a four-part series. Please read Part 2 and Part 3.这是由四个部分组成的系列文章的第一篇。 请阅读 第2 部分 和 第3部分 。 How do today’s top UX desi…

从 vue3 和 vite 源码中,我学到了一行代码统一规范团队包管理器的神器

1. 前言大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。已进行四个月了&#xff0c;很多小伙伴表示收获颇丰。想学源码&#xff0c;极力推荐之前我写…

什么事接口

假设你设计一个和人交流的程序。 先建立一个接口 interface 人 //定义接口&#xff0c;它代表一个人&#xff0c; {void Hello(); }//接口虚函数&#xff0c;用来跟这个人说话 但不同的人有不用的交流方式&#xff0c;具体方式用类来实现&#xff0c;比如。 class 美国人&#…

6个高效办公的Excel小技巧,学会让你高效办公

很多人在做Excel表格的时候&#xff0c;会出现下面这种情况&#xff1a;好不容易把内容都输入好了&#xff0c;才发现文字或是数字的排列组合需要重新调整&#xff0c;这个时候头就大了&#xff0c;到底是要一个个复制黏贴&#xff0c;还是要删除后再添加&#xff1f;不管哪种方…

unity 完美像素_像素完美

unity 完美像素从Kidpix到设计系统 (From Kidpix to design systems) Did you ever create stamps in KidPix? Kidpix is bitmap drawing software that’s been around since the nineties, and I remember many happy — more like maddening — hours creating tiny pixela…

整整4个月了,尽全力组织了源码共读活动~

大家好&#xff0c;我是若川。从8月份到现在11月结束了。每周一期&#xff0c;一起读200行左右的源码&#xff0c;撰写辅助文章&#xff0c;截止到现在整整4个月了。由写有《学习源码整体架构系列》20余篇的若川【若川视野公众号号主】倾力组织&#xff0c;召集了各大厂对于源码…

kvm 学习(二)

Linux下 如何通过命令行使用现有的镜像创建、启动kvm虚拟机 这里假定已经创建好了相应的镜像&#xff1a; eg&#xff1a;我这里制作的镜像名称为zu1-centos7.img # lszu1-centos7.img 1、拷贝这个镜像到某一个目录 cp zu1-centos7.img /data2/ 2、编写镜像的配置文件&#x…

字节内部前端开发手册(完整版)开放下载!

备战2022&#xff0c;准备好了吗&#xff1f;据字节HR部门发布的最新信息&#xff0c;2019年以来字节连续3年扩招&#xff0c;而即将到来的2022年春招前端岗位数不低于3000&#xff0c;虽连年扩招&#xff0c;但是报录比却从2019年的3%下降到今年的1%。BAT等一线大厂同样有类似…

EBS中Java并发程序笔记(1)

在Oracle EBS中的Java并发程序&#xff08;Java Concurrent Program&#xff09;是系统功能中的一个亮点&#xff0c;它的出现使得用户可以在ERP系统中运行自己定义的Java程序。本文为学习笔记&#xff0c;所以不会介绍太多背景知识。 使用Java并发程序的好处&#xff1a; 当遇…