这次的ABC三道题非常水,但是我就卡在这个D题上了QAQ

当时大概猜到了贪心,但是没有思路,后来看了一些题解才明白到底是什么意思

首先,假设我们已经处理好了前面的monsters,对于第i个monster,肯定要选择一个能力大于它能力的勇者。那么该怎么选呢,显然(用贪心的思想分析,就是勇者如果能打到a而不是b (a > b),勇者的选择就更多了,这个选择包含达到b的选择,所以可以达到全局最优)我们希望这个勇者打败的怪物越多越好,所以我们需要找到一个勇者,他的power > max(monster_power[i] ~ monster_power[i + m]),寻找能使m最大的那个勇者。

附上代码(tips:这一题用memset会超时,必须手动清空

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = ;
int pow[N], a[N];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &a[i]);
scanf("%d", &m);
int maxn = ;
for (int i = ; i < m; i++) {
int p, s;
scanf("%d %d", &p, &s);
pow[s] = max(pow[s], p);
maxn = max(maxn, s);
}
for (int i = maxn - ; i >= ; i--)
pow[i] = max(pow[i + ], pow[i]);
int monster = , ans = , len = ;
int k = maxn;
maxn = ;
while (monster < n) {
maxn = max(a[monster], maxn);
if (pow[len] >= maxn) {
len++;
monster++;
}
else if (len == ) {
ans = -;
break;
}
else {
ans++;
maxn = a[monster];
len = ;
}
}
printf("%d\n", ans + );
for (int i = ; i <= k; i++)
pow[i] = ;
}
return ;
}
//

Educational Codeforces Round 76 D的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  2. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

  3. Educational Codeforces Round 76 (Rated for Div. 2)

    传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...

  4. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest dp

    E. The Contest A team of three programmers is going to play a contest. The contest consists of

  5. 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

  6. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

  7. Educational Codeforces Round 76 (Rated for Div. 2) B. Magic Stick 水题

    B. Magic Stick Recently Petya walked in the forest and found a magic stick. Since Petya really likes ...

  8. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  9. Educational Codeforces Round 76 (Rated for Div. 2) D题

    题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...

  10. Educational Codeforces Round 76 (Rated for Div. 2) D

    D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...

随机推荐

  1. LaTeX技巧001:LaTeX中输入大小写罗马数字

    \uppercase\expandafter{\romannumeral20} \romannumeral20 前者将输入大写罗马数字20, 后者将输入小写罗马数字20.

  2. Windows10通过命令行导出笔记本电池使用信息

    powercfg /batteryreport /output "D:\Thinkpad x1c\battery_report_2020_2_25.html" 可以导出电池的电池类 ...

  3. Spring学习笔记-装配Bean-02

    什么是装配 创建应用对象之间写作关系的行为通常称为装配(wiring),这也是依赖注入(DI)的本质. Spring配置的可选方案 Spring提供了3中主要的装配机制: ● 在XML中进行显式配置. ...

  4. VMware安装CentOS系统与配置全过程

    1.需要哪些安装包 VMware Workstation 15 Pro CentOS-7-x86_64-DVD-1810 hadoop-2.7.3 apache-hive-3.1.1 jdk-8u18 ...

  5. php 公众号开发

    思考: 1,优先使用php扩展库的sdk,配合微信文档. 2,公众号开发比较简单,重在业务. 公众号关联与消息分发 <?php namespace app\wap\controller; use ...

  6. 《深入理解java虚拟机》读书笔记十——第十一章

    第十一章  晚期(运行期)优化 1.HotSpot虚拟机内的即时编译 解释器与编译器: 许多Java虚拟机的执行引擎在执行Java代码的时候都有解释执行(通过解释器执行)和编译执行(通过即时编译器产生 ...

  7. TensorFlow入门(常量变量及其基本运算)

    1.tensorflow常量变量的定义 测试代码如下: # encoding:utf-8 # OpenCV tensorflow # 类比 语法 api 原理 # 基础数据类型 运算符 流程 字典 数 ...

  8. 1307E - Cow and Treats 二分 枚举边界 容斥

    1307E - Cow and Treats 题意 有一排给定口味的草,并且给m头牛,每个牛都只吃一种口味的草,并且要吃给定数量个.现在可以安排牛从两边出发,方向向另一方向进发,每次路过符合他口味的草 ...

  9. cc.rectContainsPoint使用中发现的问题

    cc.rectContainsPoint(rect, point);此中rect常用node.getBoundingBox()方法取得,而这个方法通过node的x,y和width,height算得.也 ...

  10. batchsize用法 以及实现前向运算的矩阵乘法方式

    batchsize用法 以及实现前向运算的矩阵乘法方式 待办 使用batchsize可以把矩阵缩小,采用矩阵乘法的形式可以一次计算多个经过神经网络的结果,然后通过交叉熵进行计算总的损失得到结果. 所以 ...