Educational Codeforces Round 76 D
这次的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的更多相关文章
- Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest
Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...
- Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)
题:https://codeforces.com/contest/1257/problem/E 题意:给定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 ...
- 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
- 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) C. Dominated Subarray 水题
C. Dominated Subarray Let's call an array
- 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 ...
- Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题
A. Two Rival Students There are
- Educational Codeforces Round 76 (Rated for Div. 2) D题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
- Educational Codeforces Round 76 (Rated for Div. 2) D
D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- IDEA自定义TODO
配置自己的TODO标签 , 避免跟其他人产生错乱 打开TODO页签 , 有三种方式打开 菜单栏打开 View -> Tool Windows -> TODO 快捷键打开 Alt + 6 快 ...
- select count(1)和select count(*)的区别
select count(1) from 表a //查询时会对常数列进行统计行数select count(*) from 表a //查询时会找表a中最短的列进行统计行数 因为使用count(*)查询会 ...
- 第60届IMO 第5题
题目 巴斯银行发行的硬币在一面上铸有H,在另一面上铸有T,哈利有枚这样的硬币并将这些硬币从左至 右排成一行,他反复地进行如下操作:如果恰有k(>0)枚硬币H面朝上,则他将从左至右的第k枚硬币 ...
- id、css命名规范
main热点:hot新闻:news下载:download子导航:subnav菜单:menu子菜单:submenu搜索:search友情链接:friendlink页脚:footer版权:copyrigh ...
- Google Chrome 退出清除浏览数据
版本 79.0.3945.88(正式版本) (64 位) 设置-高级-隐私设置和安全性-网站设置-Cookie和网站数据-退出Chrome时清除Cookie及网站数据.
- sublime text 3安装html-css-js prettify后使用时报错An unhandled OS error was encountered
我在安装代码格式整理插件 html-css-js prettify 后,在使用时弹出报错提示如下图 意思大概是node.js什么路径没配置对,对于开始下载sublime text 3使用到各种插件的安 ...
- threadpool 实例介绍第二篇
- Dart单例模式最佳实践
/// Created by Capt. Michael @ CaptNotes.com on 02/17/2020. class Singleton { Singleton._(); static ...
- jQuery---突出展示案例
突出展示案例 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...
- 插入jupyter notebook代码
<iframe src="https://nbviewer.jupyter.org/gist/gaowenxin95/53408e0f1ce268430efaad2cb1f0ca4f& ...