这次的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 #2876. 「JOISC 2014 Day2」水壶 BFS+最小生成树+倍增LCA

    非常好的一道图论问题. 显然,我们要求城市间的最小生成树,然后查询路径最大值. 然后我们有一个非常神的处理方法:进行多源 BFS,处理出每一个城市的管辖范围. 显然,如果两个城市的管辖范围没有交集的话 ...

  2. node-sass pip 安装报错,提示缺少python2

    解决办法参考https://segmentfault.com/a/1190000010984731?utm_source=tag-newest npm uninstall node-sass npm ...

  3. 微信公众号和小程序可以共用access_token值吗?

    微信公众号和小程序可以共用access_token值吗? 答案:是不能的 因为两者都可通过统一接口(https://api.weixin.qq.com/cgi-bin/message/subscrib ...

  4. Ubuntu WiFi连接问题

    1,先说明下, 这种方式仅针对 RTL8723BE这款无限网卡. 先用 lspci|grep -i net 先用这个命令查询网卡型号, 我的电脑查询结果: 00:19.0 Ethernet contr ...

  5. 给静态网站的链接添加nofollow属性

    给网站的链接添加nofollow属性对SEO非常有效,如果是动态网站,实现的方法比较多,但是对于静态网站来说只能借助CSS或者JS来实现,单纯的CSS实现需要覆盖所有的链接出现位置:JS与CSS结合则 ...

  6. 使用Windows实现数据绑定

    一.绑定下拉框数据 string sql = "select * from Grade"; SqlDataAdapter sda = new SqlDataAdapter(sql, ...

  7. linux-crond_计划任务

    定时计划任务 主要文件介绍: [root@nginx ~]# ll /etc/cron* -d drwxr-xr-x. 2 root root 21 7月 11 20:28 /etc/cron.d d ...

  8. Mac 多版本 JDK 管理

    Mac 多版本 JDK 管理 1. 准备 ZSH Homebrew Oracle JDK 1.8 安装包(Homebrew 官方源和第三方源不再提供老版本的 Oracle JDK) 2. 安装 JDK ...

  9. java实现判断两个二叉树是否相同

    1.定义树节点类:节点值.左节点.右节点.构造器 2.先判断树是否为空的情况 3.树不为空时,判断节点所指的值是否相等,若相等,则递归判断节点的左右节点是否相同,相同则返回true /** * Def ...

  10. vue制作滚动条幅-跑马灯效果实例代码

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...