D - Yet Another Monster Killing Problem
题目连接:
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的更多相关文章
- 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) 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 ...
- 【CF1257D】Yet Another Monster Killing Problem【贪心】
题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过si个怪物,每个勇士只能打能力值≤pi的怪物,问最少多少天打完所有怪物 题解:贪心,每天尽可能多的去打怪,那么存一个对于长度为i ...
- Educational Codeforces Round 76 (Rated for Div. 2)
传送门 A. Two Rival Students 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/13 22:37:26 */ #incl ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- 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 号点出 ...
- HDU 6326 Problem H Monster Hunter
\(\mathtt{Problem H}\) \(\mathtt{Monster}\) \(\mathtt{Hunter}\) \(\mathcal{Description}\) 题目 给定一棵 \( ...
- hdu4970 Killing Monsters (差分数列)
2014多校9 1011 http://acm.hdu.edu.cn/showproblem.php?pid=4970 Killing Monsters Time Limit: 2000/1000 M ...
- 周赛-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) ...
随机推荐
- Salesforce LWC学习(十四) Continuation进行异步callout获取数据
本篇参考: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_continua ...
- C 2012年笔试题
1指出程序段中的错误:分析错误的原因,并进行修改 1.1函数 swap 将两个字符串(字符数组作实参,长度不超过 100)的内容进行交换 void swap(char *pa,char *pb) { ...
- 彻底明白equals和hashCode
equals和hashCode方法 equals 我们知道equals是用来比较两个对象是否相等的,比如我们常用的String.equals方法 @Test public void test() { ...
- UVa 11059 最大乘积 java 暴力破解
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- 曹工说Spring Boot源码(28)-- Spring的component-scan机制,让你自己来进行简单实现,怎么办
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
- 使用maven-pom进行依赖管理与自动构建
使用maven-pom进行依赖管理与自动构建 span.kw { color: #007020; font-weight: bold; } /* Keyword */ code > span.d ...
- Downgrade ASM DATABASE_COMPATIBILITY (from 11.2.0.4.0 to 11.2.0.0.0) on 12C CRS stack.
使用Onecommand完成快速Oracle 12c RAC部署后 发现ASM database compatibilty无法设置,默认为11.2.0.4.0. 由于我们还有些数据库低于这个版本,所以 ...
- [poj1797]Heavy Transportation<最大生成树prim&kruskal>
题目链接:http://poj.org/problem?id=1797 题意:给定n个点,m条边,每条边连接两点切有权值.求点1到点n的路径的上的最小边的值最大... 翻别人博客找到的题,方法挺多的, ...
- Windows 7 NVMe补丁(包括官网下载链接)
随着NVMe固态硬盘的普遍,很多想使用Windows 7,又想使用NVMe固态硬盘的,不得不打两个NVMe补丁 这两个补丁主要是:KB2990941和KB3087873 32位 百度网盘 64位 百度 ...
- Sql练习201908131742
orderdt_jimmy表结构: sql查询: then amount end) t1, then amount end) t2, then amount end) t3 from orderdt_ ...