题意:

给你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. 关于Python编码这一篇文章就够了

    概述 在使用Python或者其他的编程语言,都会多多少少遇到编码错误,处理起来非常痛苦.在Stack Overflow和其他的编程问答网站上,UnicodeDecodeError和UnicodeEnc ...

  2. PAT(B) 1078 字符串压缩与解压(Java)

    题目链接:1078 字符串压缩与解压 (20 point(s)) 题目描述 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示 ...

  3. oracle随笔之提示“ORA-01002: 提取违反顺序”

    如果存储过程中有插入语句并且没有写COMMIT的话在调试时会提示:“ORA-01002: 提取违反顺序”

  4. Angular 学习笔记 ( 我追的 feature 和 bug )

    Angular 有许多功能还不齐全,也有不少 bug 让人很头疼,所以这里做一些记入 Angular Bug 1.input type="number", valueChanges ...

  5. .net SHA-256 SHA-1

    Framework 4.5 uses SHA-256 algorithm for the signature, and 4.0 uses SHA-1.

  6. CentOS 6.x 配置iptables

    CentOS 6.x 配置iptables 来源 https://www.cnblogs.com/chillax1314/p/7976067.html iptables -P INPUT DROP-- ...

  7. How to delete SAP* from HANA Tenant database

    How to delete SAP* from HANA Tenant database 1.如何登录HANA的多租户(TDC)数据库 使用SAPS4端对应的SAP账户,比如S4D的账户为s4dadm ...

  8. PX4/Pixhawk uORB

    PX4/Pixhawk的软件体系结构主要被分为四个层次 应用程序的API:这个接口提供给应用程序开发人员,此API旨在尽可能的精简.扁平及隐藏其复杂性 应用程序框架:这是为操作基础飞行控制的默认程序集 ...

  9. java线程中如何使用spring依赖注入

    实现一个线程继承了Thread或实现Runnable接口,想在run方法中使用spring依赖注入(操作数据库),此时报错为空指针,就是说没有注入进来. 实验了几种方式,分别说一下优缺点. 1:写了工 ...

  10. [LeetCode] 300. 最长上升子序列 ☆☆☆(动态规划 二分)

    https://leetcode-cn.com/problems/longest-increasing-subsequence/solution/dong-tai-gui-hua-she-ji-fan ...