这次的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. LOJ #3119. 「CTS2019 | CTSC2019」随机立方体 组合计数+二项式反演

    好神的一道计数题呀. code: #include <cstdio> #include <algorithm> #include <cstring> #define ...

  2. 安装AB到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:httpd-tools-2.4.6 硬件要求:无 安装过程 1.安装YUM-EPEL源 HTTP ...

  3. arcgis10.2下载安装教程

    ArcGIS Desktop 10.2 完全安装教程(含win7 32/64位+下载地址+亲测可用) 时间: 2014年08月20日   阅读: 622,262   分类: GIS探秘   标签: A ...

  4. 错误 CS8107 C# 7.0 中不支持功能“xxxxxx”。请使用 7.1 或更高的语言版本。

    解决方法:项目右键属性 —> 生成 —> 找到最下面的高级按钮,点击高级按钮 —> 常规 —> 语言版本 —> 选择 C#最新次要版本,或者比当前版本更高的版本即可,点击 ...

  5. 每天进步一点点------Modelsim添加Xilinx仿真库的详细步骤

    Modelsim,可以选型SE和XE两个版本.Modelsim XE可以直接被ISE调用,而Modelsim SE需要手动添加仿真库.但SE版和OEM版在功能和性能方面有较大差别,比如对于大家都关心的 ...

  6. jQuery---京东轮播图

    京东轮播图 有个计数的,点右边,计数增加,判断计数是否超过总的长度,超过设置计数为0,再设置当前的图片动画,兄弟的图片动画 左边点击同理,计数是--,判断计数是否等于-1,等于则reset计数为总长度 ...

  7. 关闭 APIPA

    遇到的问题:我在网卡2上设置了静态ip,可是出现了一个奇怪的ip地址169.254.*.*,如下图. 解决方法:关闭APIPA功能 按照下述的做法,自己在win7企业版上尝试了下,有效.不再出现169 ...

  8. LaTeX技巧005:定制自己炫酷的章节样式实例

    示例一: 实现代码: \usepackage[Lenny]{fncychap} 示例二: 实现代码: \usepackage[avantgarde]{quotchap} \renewcommand\c ...

  9. shell变量内字符替换和变量字符修改

    vi test.sh a= #将${a}里的第一个123替换为321 b=${a//}; echo "echo variable a" echo $a echo "ech ...

  10. 微信小程序中的左右联动

    微信小程序端的左右联动-滚动效果插件: 效果图如下:                                                                          ...