这次的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. sql注入文件写入和读取

    系统固定文件路径:https://blog.csdn.net/ncafei/article/details/54616826 /etc/passwd c:/windows/win.ini 文件读取使用 ...

  2. 洛谷 P4708 画画

    题意 在所以置换下,本质不同的各个极大连通子图均含有欧拉闭迹的\(n\)阶图个数 做法 务必先做完这题再看此题解,因为会省略大部分分析了 仍是从边入手,隔外限制:各个点度数是偶数 某个因子内\((m= ...

  3. P1522 牛的旅行

    P1522 牛的旅行 Cow Tours 提交 11.44k 通过 4.97k 时间限制 1.00s 内存限制 125.00MB 题目提供者洛谷 难度提高+/省选- 历史分数100 提交记录 查看题解 ...

  4. ansi sql 语法 切换为 oracle 语法

        语句粘贴到 工作表 打开查询构建器 勾选 创建oracle连接 over     sql dev 的语法设置调整,否则表别名会右对齐   下面是 转换后的结果,是不是看得舒服多了

  5. jQuery---内容复习

    内容复习 1. 操作样式 (5) 1.1 css操作 设置单个样式 设置多个样式 获取样式 css(name, value) :设置单个样式 css(obj):设置多个样式 css(name):获取样 ...

  6. CSS隐藏元素的五种方法

    1.opacity:0 2.visibility:hidden 3.diaplay:none 4.position:absolute display display属性依照词义真正隐藏元素.将disp ...

  7. php 对象、json 、XML、数组互转

    对象转json $json=json_encode($postObj,JSON_FORCE_OBJECT); json转对象 $obj=json_encode($json); json转数组 $arr ...

  8. Python 高维数组“稀疏矩阵”scipy sparse学习笔记

    scipy 里面的sparse函数进行的矩阵存储 可以节省内存 主要是scipy包里面的 sparse 这里目前只用到两个 稀疏矩阵的读取 sparse.load() 转稀疏矩阵为普通矩阵 spars ...

  9. Python元组详解

    元组的特征 元组类型的名字是tuple 元组的一级元素不可被修改.不能增加或者删除: 元组和列表的书写区别是将中括号改成了小括号: 为方便区分元组和普通方法的参数,一般在元组的最后一个元素后保持加一个 ...

  10. BOM笔记

    目录 BOM (浏览器对象模型) 简介 window对象 子对象 history 子对象 lacation 子对象 navigator 子对象 screen 子对象 frames BOM (浏览器对象 ...