Codeforces 1257D - Yet Another Monster Killing Problem
题意:
有\(n\)个怪物,每个怪物有攻击力\(a_i\)点;有\(m\)个英雄,每个英雄有攻击力\(p_i\)点,耐力\(s_{i}\)点。
怪物需要被依次杀死(按输入顺序)。
每一天可以挑选一个英雄去杀怪物,他可以杀死的怪物攻击力小于等于他本身(即\(a\leq p\)),每天最多可以杀死\(s\)个怪物。(每个英雄可以使用任意次)
问最少需要多少天可以杀死所有怪物(不能则输出\(-1\))。
分析:
\((1)\)我们找到怪物的最大攻击力和英雄的最大攻击力,判断是否要输出\(-1\)。
\((2)\)将英雄按攻击力\(p\)值排序,我们可以发现对于英雄\(b[i]\)而言,如果对于\(i<j\leq m\),且有\(b[i].s<b[j].s\),我们可以选择英雄\(j\),而不是英雄\(i\),那么我们可以把\(b[i].s\)替换为\(b[j].s\)(意思为选择英雄\(i\)时选择英雄\(j\))。
\((3)\)因此我们进行后缀操作将\(b[i].s\)改为英雄\(i\)~\(n\)中最大的耐力值,以便进行下一步。
\((4)\)对于某个怪物而言,我们可以找到一个英雄,他的攻击力刚好大于等于该怪物(二分)。我们上一步将该英雄的耐力改为了后缀最大值,那么我们便选择这个英雄。
\((5)\)我们从第一天开始,枚举每一个怪物,找到当前天我们可以杀死最多怪物的英雄,如果对于某个怪物而言,杀死他的人的耐力(我们进行了后缀操作)不足以支撑该天,我们将该怪物放到下一天,并重复操作,直至杀死所有怪物。因此我们需要保存的量有:当前的天数\(k\),昨天杀死的最后一只怪物的编号\(last\),今天所能杀死的最多怪物数(表现为所需要的最小耐力)\(minn\)。
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define LL long long
using namespace std;
const int maxn = (ll) 2e5 + 5;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
struct node {
int p, s;
bool operator<(const node &b) {//用做排序
return p < b.p;
}
} b[maxn];
bool cmp(const node &x, int y) {//用做二分
return x.p < y;
}
int a[maxn];
int main() {
start;
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
int maxa = 0, maxs = 0;//用做判-1
for (int i = 1; i <= n; ++i) {
cin >> a[i];
maxa = max(maxa, a[i]);
}
int m;
cin >> m;
for (int i = 1; i <= m; ++i) {
cin >> b[i].p >> b[i].s;
maxs = max(maxs, b[i].p);
}
if (maxa > maxs) {
cout << -1 << '\n';
continue;
}
sort(b + 1, b + m + 1);
for (int i = m - 1; i >= 1; --i)//后缀操作
b[i].s = max(b[i].s, b[i + 1].s);
int k = 1;
int last = 0;
int minn = inf;
for (int i = 1; i <= n; ++i) {
int t = lower_bound(b + 1, b + m + 1, a[i], cmp) - b;//刚好能杀死该怪物的英雄编号
minn = min(b[t].s, minn);//今天所需要的最小耐力
if (minn + last < i) {//将这只怪物放到明天杀
minn = b[t].s;
++k;
last = i - 1;
}
}
cout << k << '\n';
}
return 0;
}
本场比赛\(D\)和\(E\)惨痛教训:玩后缀一定要注意边界!!!
Codeforces 1257D - Yet Another Monster Killing Problem的更多相关文章
- Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem 贪心
D. Yet Another Monster Killing Problem You play a computer game. In this game, you lead a party of
- Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem
You play a computer game. In this game, you lead a party of mm heroes, and you have to clear a dunge ...
- D - Yet Another Monster Killing Problem
题目连接: https://codeforces.com/contest/1257/problem/D 题目大意: n个怪兽,m个英雄,每个怪兽有一定的能力值,每个英雄有一定的能力值和一定的耐力值.耐 ...
- 【CF1257D】Yet Another Monster Killing Problem【贪心】
题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过si个怪物,每个勇士只能打能力值≤pi的怪物,问最少多少天打完所有怪物 题解:贪心,每天尽可能多的去打怪,那么存一个对于长度为i ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...
- codeforces D. Pashmak and Parmida's problem
http://codeforces.com/contest/459/problem/D 题意:给你n个数,然后统计多少组(i,j)使得f(1,i,ai)>f(j,n,aj); 思路:先从左往右统 ...
- CodeForces 459D Pashmak and Parmida's problem
Pashmak and Parmida's problem Time Limit:3000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces Beta Round #2 C. Commentator problem 模拟退火
C. Commentator problem 题目连接: http://www.codeforces.com/contest/2/problem/C Description The Olympic G ...
- Codeforces 954I Yet Another String Matching Problem(并查集 + FFT)
题目链接 Educational Codeforces Round 40 Problem I 题意 定义两个长度相等的字符串之间的距离为: 把两个字符串中所有同一种字符变成另外一种,使得两个 ...
随机推荐
- 2014年蓝桥杯C/C++大学B组省赛真题(六角填数)
题目描述: 如图[1.png]所示六角形中,填入1~12的数字. 使得每条直线上的数字之和都相同. 图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少? 分析:先将a数组初始化为1-12 ...
- allure的安装与配置
一.安装配置JDK 说明:以win10系统为例 1.Oracle官网下载JDK:https://www.oracle.com/java/technologies/downloads/ 请下载安装JDK ...
- 【pandas基础】--目录(完结)
pandas 基础内容的目录: 概述 pandas 主要功能和应用场景的介绍. 数据读取 数据读取是第一步,只有成功加载数据之后,后续的操作才有可能. pandas 可以读取和导入各种数据格式的数据, ...
- ASP.NET Core 6框架揭秘实例演示[37]:重定向的N种实现方式
在HTTP的语义中,重定向一般指的是服务端通过返回一个状态码为3XX的响应促使客户端像另一个地址再次发起请求,本章将此称为"客户端重定向".既然有客户端重定向,自然就有服务端重定向 ...
- 【HarmonyOS】一文教你如何在低代码项目中跳转H5页面
[关键字] 元服务.低代码.H5页面跳转.WebView [1.写在前面] 今天我们来实现一个在低代码项目中通过按钮跳转到H5页面的功能,本项目是基于API6的JS工程,我们的实现思路是在页面B中 ...
- 使用EasyExcel对excel数据进行相似度判断
@Data public class ExeclDto { /** * execl表 */ private String filename; /** * 需要匹配的工作表名 */ private St ...
- 【Azure 媒体服务】Azure Media Player 在Edge浏览器中不能播放视频问题的分析与解决
问题描述 使用Azure Media Service 制作视频点播服务,在客户端使用 Azure Media Player 播放器在 Edge 浏览器中播放视频时候遇见无法播放的问题: 错误信息: T ...
- C# - ConcurrentDictionary 并发场景使用注意事项
1 自身作为 Enumerable 的遍历 自身作为可遍历对象,键值对为元素进行遍历,是线程安全的,但不提供快照,遍历过程中集合产生变更会直接反馈至此次遍历过程中.但并不一定能够保障获取数据的过程中, ...
- 浏览器手动设置Cookie
浏览器手动设置Cookie js代码: document.cookie="{KEY}={Value}": 可多次执执行.
- CF1728A Colored Balls: Revisited题解
去我的Blog观看 修改时间:2022/9/11修改了格式与标点 修改时间:2022/9/13修改了个别不严谨的语句 题目大意 有 \(n\) 种颜色的球,颜色为 \(i\) 的球为 \(cnt_i\ ...