题意:

给你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题的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  2. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

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

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

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

  6. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

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

  8. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  9. Educational Codeforces Round 76 (Rated for Div. 2) D

    D题 原题链接 题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天) 思路:因为怪兽是不 ...

随机推荐

  1. 使用TypeScript创建React Native

    ⒈初始化 React Native环境 参考https://reactnative.cn/docs/getting-started.html ⒉安装React Native官方的脚手架工具 npm i ...

  2. SQL语言(二)

    SQL约束与策略 create table student( id int primary key, //主键约束 name ) not null, //非空约束 idCard ) unique, / ...

  3. RAP2 前后端开发利器搭建

    RAP2 是一个api管理系统,前后端协作开发的利器. 在线体验地址http://rap2.taobao.org Web接口管理工具,开源免费,接口自动化,MOCK数据自动生成,自动化测试,企业级管理 ...

  4. Linux上安装pstree命令(-bash: pstree: command not found)

    一.pstree命令的安装 1.在 Mac OS上 brew install pstree 2.在 Fedora/Red Hat/CentOS yum -y install psmisc 3.在 Ub ...

  5. 写一个RD一般需要多久?在迭代中新增的需求如何处理?如何做好项目管理?

    最近总是有些初入行的小伙们,经常会问我一些他们在工作工作的中疑问,我今天挑选出几个比较典型的问题和大家一起来讨论下. 问题如下: 写一个PRD一般需要多久? 在迭代中新增的需求如何处理? 如何做好项目 ...

  6. 监控SQL:执行表中所有sql语句、记录每个语句运行时间(3)

    原文:监控SQL:执行表中所有sql语句.记录每个语句运行时间(3) 通过执行一个 带参数的存储过程  exec  OpreateTB('OpreateUser','IsRun')  更新表的数据 表 ...

  7. 字节数组(byte[])与16进制字符串转换

    /// <summary> /// 转换扩展类 /// </summary> public static class ConvertExtend { /// <summa ...

  8. POJ1222、POJ3279、POJ1753--Flip

    POJ1222-EXTENDED LIGHTS OUT POJ3279-Fliptile POJ1753-Flip Game 为什么将着三个题放一起讲呢?因为只要搞明白了其中一点,就可以一次3ac了- ...

  9. POJ3368(Frequent values)--线段树

    题目在这里 3368 Accepted 7312K 1829MS C++ 6936B 题意为给你一组数据,再给定一组区间,问你这个区间内出现次数最多的元素的次数是多少. 我还记得这题是学校校赛基础的题 ...

  10. BASIS小问题汇总1

    try to start SAP system but failed 2019-04-04 Symptom: when i tried to start SAP system, using the c ...