Educational Codeforces Round 76 (Rated for Div. 2) D题
题意:
给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a【i】,你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打好几关(只要在疲劳范围内),打不过的话英雄就结束今天的挑战,转到第二天。问最少需要出战多少英雄才能通过所有关卡。
思路:先用一个数组。跑出相同忍耐值时,攻击力越大。然后·跑出这个数组的后缀pre数组,pre数组的含义是:忍耐值一定,攻击力最大。然后通过O(n)的复杂度跑·怪物的数组。当怪物的a【i】值大于pre数组在上一天的攻击力时,进入下一天。【变相的二分】【题目比较难叙述QAQ】
代码:
#include<bits/stdc++.h> using namespace std; #define int long long
const int N=22e4;int n;
int arr[N];
int pre[N];
int str[N];
int slove(){
int ans=;//总天数
int last_time=-;
int maxn=;
for(int i=;i<n;i++){
maxn=max(maxn,arr[i]);
if(pre[i-last_time]<maxn){
last_time=i-;
ans++;
maxn=arr[i];
}
if(pre[]<arr[i]){
return -;
}
}
return ans;
}
signed main(){
ios::sync_with_stdio();
int _;
cin>>_;
while(_--){
cin>>n;
int maxn1=,maxn2=;
for(int i=;i<=n+;i++)
arr[i]=,str[i]=,pre[i]=;
for(int i=;i<n;i++){
cin>>arr[i];
maxn1=max(maxn1,arr[i]);
}
int m;
cin>>m;
for(int i=;i<m;i++){
int x,y;
cin>>x>>y;
maxn2=max(maxn2,x);
pre[y]=max(pre[y],x);//相同忍耐值时,攻击力越大
}
if(maxn1>maxn2){
cout<<"-1"<<'\n';
continue;
}
for(int i=n-;i>;i--){
pre[i]=max(pre[i+],pre[i]);//
}
cout<<slove()<<'\n';
}
return ;
}
Educational Codeforces Round 76 (Rated for Div. 2) 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
D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- 简单理解JavaScript原型链
简单理解原型链 什么是原型 ? 我是这样理解的:每一个JavaScript对象在创建的时候就会与之关联另外一个特殊的对象,这个对象就是我们常说的原型对象,每一个对象都会从原型"继承" ...
- 杭电2577 多数组dp问题
Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...
- WPF打印控件内容
当我们想打印控件内容时,如一个Grid中的内容,可以用WPF中PrintDialog类的PrintVisual()方法来实现 界面如下: XAML代码如下 <Grid> <Grid. ...
- POJ1475(Pushing Boxes)--bbffss
题目在这里 题目一看完就忙着回忆童年了.推箱子的游戏. 假设只有一个箱子.游戏在一个R行C列的由单位格子组成的区域中进行,每一步, 你可以移动到相邻的四个格子中的一个,前提是那个格子是空的:或者,如果 ...
- Django Rest framework序列化流程
目录 一 什么是序列化 二 Django REST framework配置流程之Serializer 三 Django REST framework配置流程之ModelSerializer 一 什么是 ...
- 在Eclipse配置Tomcat服务器+JSP实例创建
欢迎任何形式的转载,但请务必注明出处. 1.jdk安装及环境配置 点击进入教程 2.Eclipse安装 点击进入官网下载 注意下载完成打开.exe后,出现的界面,有很多版本供选择.选择下图版本 3.T ...
- Linux 之 用户、用户组以及权限
拥有者(user),拥有组(group),其他人(other) 由于Linux是一个多人多任务的系统,因此经常会出现同一台机器同时有多个人进行操作,为了考虑每个人的隐私权以及每个人喜好的工作环境,所以 ...
- Python基础Day5
一.字典 ①字典是python的基础数据类型之一 ②字典可以存储大量的数据,关系型数据 ③字典也是python中唯一的映射类的数据类型 字典是以键值对的形式存在的,{键:值} 字典的键必须是不可变的数 ...
- Python语言程序设计:Lab5
Programming Create a Class Student which should have the following information:Parameters passed to ...
- JS知识体系【JQ】附加理论+视频地址铺助学习
理论部分:https://www.jianshu.com/p/e10792076c6e //不吃鱼的猫_8e95---简书平台 https://www.cnblogs.com/hongqin/p/5 ...