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个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...
随机推荐
- 给定a、b两个文件,各存放50亿个url,每个url各占64字节,内存限制是4G,让你找出a、b文件共同的url?
package com.hadoop.hdfs; import org.apache.hadoop.yarn.webapp.hamlet.Hamlet; import org.junit.Test; ...
- 又是a+b
题目描述: 给定两个整数 a, b (a, b 均不超过 int 类型的表示范围),求出 a + b 的和.输入描述: 多组输入,每组输入为一行,里面有 2 个数 a, b.输出描述: 对于每一组输入 ...
- WUSTOJ 1298: 操作格子(Java)
题目链接:
- 十六、USB驱动
一.USB固件和USB传输方式 USB固件: USB固件一般不需要我们编写,在此不做程序分析. USB固件中包含USB设备的出厂信息,如厂商ID.产品ID.主版本号和次版本号等.这就是为什么当我们把U ...
- spring整合MQ
---恢复内容开始--- 一. 导入依赖 <dependencies> <!-- ActiveMQ客户端完整jar包依赖 --> <dependency> < ...
- K380键盘IOS使用
- #448 div2 a Pizza Separation
A. Pizza Separation time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- 在论坛中出现的比较难的sql问题:10(删除多表中的同一个外键)
原文:在论坛中出现的比较难的sql问题:10(删除多表中的同一个外键) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得有 ...
- Python之Django
一.Django是一个开放源代码的Web应用框架,由Python写成.采用了MTV的框架模式,即模型M,视图V和模版T.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CM ...
- U盘安装Ubuntu14.04&配置远程win10远程连接
1.U盘安装Ubuntu:https://blog.csdn.net/baigoocn/article/details/26561473 2.win10远程访问Ubuntu系统:https://www ...