题目连接:

https://codeforces.com/contest/1257/problem/D

题目大意:

n个怪兽,m个英雄,每个怪兽有一定的能力值,每个英雄有一定的能力值和一定的耐力值。耐力值得含义是每天可以击杀怪兽的最多数目。当英雄的能力值大于怪兽的能力值时,英雄可以击杀怪兽,然后问击杀

所有的怪兽所需要的最短时间,如果不能击杀所有怪兽,输出-1;

思路:主要是一个对一个mx数组的理解mx[i]的含义是在耐力值为i的情况下,英雄的最大能力。

#include<bits/stdc++.h>
using namespace std;
const int N=2E5+;
int arr[N];
int mx[N];
int p[N],abi[N];
void solve(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) mx[i]=;
for(int i=;i<=n;i++) scanf("%d",&arr[i]);
int m;
scanf("%d",&m);
for(int i=;i<=m;i++){
scanf("%d%d",&abi[i],&p[i]);
mx[p[i]]=max(mx[p[i]],abi[i]);
}
//一天可以击杀i个的英雄一定可以击杀i-1个。
//即mx[i]指的是耐力值大于等于i的英雄的最大能力。
for(int i=n-;i>=;i--) mx[i]=max(mx[i],mx[i+]);
int day=,j=;
bool flag=false;
for(int i=;i<=n;){
day++;
flag=false ;
int maxn=;
int tmp=i;
//一天可以击杀的最大数量,找到这几个怪兽的最大能力,然后在mx数组中查找击杀x个怪兽英雄的最大能力。
while(){
maxn=max(arr[i],maxn);
if(maxn>mx[i-tmp+]) break;
i++;
flag=true;
}
if(!flag) break;
}
if(!flag) day=-;
printf("%d\n",day);
return ;
} int main(){
cin.tie();
int t;
scanf("%d",&t);
while(t--) solve();
return ;
}

D - Yet Another Monster Killing Problem的更多相关文章

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

  2. Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem

    You play a computer game. In this game, you lead a party of mm heroes, and you have to clear a dunge ...

  3. 【CF1257D】Yet Another Monster Killing Problem【贪心】

    题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过si个怪物,每个勇士只能打能力值≤pi的怪物,问最少多少天打完所有怪物 题解:贪心,每天尽可能多的去打怪,那么存一个对于长度为i ...

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

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

  5. CF Educational Round 78 (Div2)题解报告A~E

    CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students​ 依题意模拟即可 #include<bits/stdc++.h> us ...

  6. HDU 6326.Problem H. Monster Hunter-贪心(优先队列)+流水线排序+路径压缩、节点合并(并查集) (2018 Multi-University Training Contest 3 1008)

    6326.Problem H. Monster Hunter 题意就是打怪兽,给定一棵 n 个点的树,除 1 外每个点有一只怪兽,打败它需要先消耗 ai点 HP,再恢复 bi点 HP.求从 1 号点出 ...

  7. HDU 6326 Problem H Monster Hunter

    \(\mathtt{Problem H}\) \(\mathtt{Monster}\) \(\mathtt{Hunter}\) \(\mathcal{Description}\) 题目 给定一棵 \( ...

  8. hdu4970 Killing Monsters (差分数列)

    2014多校9 1011 http://acm.hdu.edu.cn/showproblem.php?pid=4970 Killing Monsters Time Limit: 2000/1000 M ...

  9. 周赛-Killing Monsters 分类: 比赛 2015-08-02 09:45 3人阅读 评论(0) 收藏

    Killing Monsters Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. ubuntu 16.04配置svn服务器

    为了操作方便,使用root登录服务器. 一.安装svn服务器 -->apt-get install subversion 二.创建svn版本库,存放需要管理内容路径 -->mkdir sv ...

  2. Hive常用命令及作用

    1-创建表 -- 内部表 create table aa(col1 string,col2 int) partitioned by(statdate int) ROW FORMAT DELIMITED ...

  3. Ubuntu18.04下安装MySQL5.7(支持win10-wsl环境)

    注意: 本文操作环境为win10系统wsl下的Ubuntu18.04,对于原生的Ubuntu18.04同样适用.MySQL默认版本为5.7,其他版本不适用. 安装步骤 1.更新源: sudo apt ...

  4. Python-类的特性

    ------------恢复内容开始------------ 类及类的定义 Cat类 类的特殊方法-构造函数.析构函数 class Cat: # 构造函数 def __init__(self, nam ...

  5. python之装饰器的进阶

    一.带参数的装饰器 (必须会) 针对不同的app的验证,比如:天猫和天猫超市,京东商城和京东超市 def wrapper_out(n): print(n) def wrapper(f): def in ...

  6. 一文彻底搞懂BP算法:原理推导+数据演示+项目实战(上篇)

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 反向传播算法(Backpropagation Algorithm, ...

  7. 前端学习(3)-CSS

    一 CSS CSS是Cascading Style Sheets的缩写,层叠样式表,用来控制网页数据的显示,可以使网页的显示与数据内容分离. 二 引入方式 (1)行内式:在标记的style属性中设置C ...

  8. 15.自动部署web工程

    用maven自动部署web工程 在pom.xml中写入以下: <build> <!--最终名称,进入网页时有http://localhost:8080/xxx/--> < ...

  9. js拖拽效果的实现及原理

    元素拖拽分成3个步骤:按下鼠标,移动鼠标,松开鼠标. 拖拽原理:按下拖拽元素后开始监听文档中鼠标移动事件,然后再监听鼠标松开事件:鼠标移动时,元素div要随着鼠标一起移动,需要计算元素div位移的距离 ...

  10. B - Charlie's Change

    Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffe ...