题目链接

传送门

题意

你有\(n\)只怪,每只怪的伤害为\(a_i\),对手有\(m\)只怪,每只怪的伤害为\(b_i\),对手的怪有普通状态和防守状态(普通状态:如果你用攻击力为\(a_i(a_i\geq b_j)\)的怪去攻击对手第\(j\)只怪将会给对手造成\(a_i-b_j\)的伤害;防守状态则不会造成\(a_i-b_j\)的伤害),每只怪只能使用一次,怪一旦死亡就会消失。

用攻击力为\(x\)的怪去打攻击力为\(y(x\leq y\),\(x\geq y\)的情况上面说了\()\)的怪会有以下两种情况:

  • \(x<y\):对手不受到任何伤害,自己的怪死亡;
  • \(x=y\):对手不受到任何伤害,双方的怪死亡;

如果对手所有的怪都死亡了,那么你就可以直接攻击对手且伤害为你的怪的伤害值。

问你你能给对手造成的最大伤害值是多少。

思路

本题分两种情况进行考虑:

  • 全部的怪都去打对手普通状态的怪,注意这种情况下不能直接攻击对手。
  • 将防守状态和普通状态的怪都打死,然后用剩余的怪去打对手。

我们知道用剩余怪中伤害值大的去打对手剩余怪中伤害值大的是最优解(如果用伤害值大的去打其他怪的话,到后面可能会导致有怪打不死对手伤害值高的怪),因此用两个双指针瞎搞就可以了。

代码实现如下

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n, m;
vector<int> vec1, vec2;
int a[maxn], vis1[maxn], vis2[maxn]; struct node {
int val, pos;
bool operator < (const node& x) const {
return val < x.val;
}
}pp[maxn]; int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif // ONLINE_JUDGE
scanf("%d", &t);
int icase = 0;
while(t--) {
scanf("%d%d", &n, &m);
vec1.clear(), vec2.clear();
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
vis1[i] = 0;
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= m; ++i) {
scanf("%d", &pp[i].val);
vis2[i] = 0;
}
int num = 0, flag = 1;
for(int i = 1; i <= m; ++i) {
scanf("%d", &pp[i].pos);
if(pp[i].pos) ++num, flag = 0;
}
sort(pp + 1, pp + m + 1);
if(n > num) {
for(int i = 1, j = 1; i <= n; ++i) {
while(!pp[j].pos) ++j;
if(j > m) break;
if(a[i] >= pp[j].val) {
--num;
vis1[i] = vis2[j] = 1;
++j;
}
}
}
for(int i = 1; i <= n; ++i) {
if(vis1[i]) continue;
vec1.emplace_back(a[i]);
}
for(int i = 1; i <= m; ++i) {
if(vis2[i] || pp[i].pos) continue;
vec2.emplace_back(pp[i].val);
}
LL ans1 = 0, ans2 = 0;
for(int i = vec1.size() - 1, j = vec2.size() - 1; i >= 0; --i) {
while(j >= 0 && vec1[i] < vec2[j]) --j;
if(j < 0 && num == 0) {
ans1 += vec1[i];
continue;
} else if(j < 0) continue;
ans1 += vec1[i] - vec2[j];
--j;
}
for(int i = n, j = m; i >= 0; --i) {
while(j > 0 && (pp[j].pos || pp[j].val > a[i])) --j;
if(j <= 0 && flag) {
ans2 += a[i];
continue;
} else if(j <= 0) continue;
ans2 += a[i] - pp[j].val;
--j;
}
printf("Case %d: %lld\n", ++icase, max(ans1, ans2));
}
return 0;
}

Strength(HDU6563+2018年吉林站+双指针瞎搞)的更多相关文章

  1. 2018 CCPC 吉林站 H Lovers

    2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, ...

  2. Justice(HDU6557+2018年吉林站+二进制)

    题目链接 传送门 题意 给你\(n\)个数,每个数表示\(\frac{1}{2^{a_i}}\),要你把这\(n\)个数分为两堆,使得每堆的和都大于等于\(\frac{1}{2}\). 思路 首先我们 ...

  3. Lovers(HDU6562+线段树+2018年吉林站)

    题目链接 传送门 题意 初始时有\(n\)个空串,然后进行\(q\)次操作,操作分为以下两种: wrap l r x:把\(l,r\)中的每个字符串的首尾都加入\(x\),如\(s_i=121,x=3 ...

  4. The Tower(HDU6559+2018年吉林站+数学)

    题目链接 传送门 题意 告诉你圆锥的底部圆的半径和圆锥的高,再给你一个点的坐标及其运动向量,问你这个点什么时候会与这个圆锥相撞. 思路 比赛场上二分一直没过但是有人二分过了,今天再写这题想再试下二分, ...

  5. 2018 CCPC 吉林站 H Lovers || HDU 6562 (线段树哦)

    http://acm.hdu.edu.cn/showproblem.php?pid=6562 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, 使得这个数变成 dsiddsid的形式 ...

  6. 2018年9月22日CCPC吉林站参赛总结

    发现思维题是硬伤,代码能力是硬伤,对知识点的理解不深刻是硬伤 接下来要做的就是 1.熟悉每一个知识点,把每一个知识点和实现它的代码联系在一起学习 2.多见题,看看他们是怎么考察这些知识点的,等比赛的时 ...

  7. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

  8. URAL 1203. Scientific Conference(瞎搞)

    题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...

  9. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

随机推荐

  1. [ ceph ] BlueStore 存储引擎介绍

    为什么需要 BlueStore 首先,Ceph原本的FileStore需要兼容Linux下的各种文件系统,如EXT4.BtrFS.XFS.理论上每种文件系统都实现了POSIX协议,但事实上,每个文件系 ...

  2. TELNET可以连通但无法创建数据库连接(Oracle)

    问题描述: 近期客户方进行了网络调整,申请A服务器的1521端口开通后,telnet可以访问,但是SQLPLUS.PLSQL等工具一直无法创建相应连接,提示连接超时. 问题排查: 对开放端口的所有服务 ...

  3. SonarQube - 安装与运行SonarQube

    1 - 下载SonarQube SonarQube有多个版本,其中CE(Community Edition)版本免费开源,其余的开发者版本.企业版本和数据中心版本都是收费版本. 官网下载:https: ...

  4. QQ自动强制加好友代码html

    鲜为人知的QQ自动强制加好友代码 是的,你也许见过强行聊天的代码: tencent://Message/?Uin=574201314&websiteName=www.oicqzone.com& ...

  5. Ubuntu下安装与卸载opencv模块

    opencv安装 因工程需要,想在python中调用opencv import cv2 现在记录一下如何在Linux系统(ubutun)下安装该模块: 参考了一篇博客:http://blog.csdn ...

  6. RocketMQ 4.5.1 双主双从异步复制环境搭建

    基础环境 操作系统:CentOS7 实例:192.168.63.129,192.168.63.130,192.168.63.131,192.168.63.132 Java:jdk-8u191-linu ...

  7. delphi xe6 窗口 visible 不能隐藏 解决

    delphi xe6 窗口 visible 不能隐藏 解决 在工程代码里面加上 Application.ShowMainForm := false;

  8. 生意bisynes商业

    1.Of, to, pertaining to or utilized for purposes of conducting trade, commerce, governance, advocacy ...

  9. vue css module

    步骤 module <style> -> <style module> class='header' -> :class='$style.header' <t ...

  10. gym101480

    A. ASCII Addition 模拟 #include <iostream> #include <sstream> #include <algorithm> # ...