Educational Codeforces Round 76 (Rated for Div. 2) D
D题
题意:就是给你n个怪兽有一个属性(攻击力),m个英雄,每个英雄有两种属性(分别为攻击力,和可攻击次数),当安排最好的情况下,最少的天数(每选择一个英雄出战就是一天)
思路:因为怪兽是不可排序的,我就把英雄按类分装,运用贪心思想来做,每一个攻击次数下都有一个或多个英雄,我们都选择攻击力最高的英雄来代表,然后就暴力枚举所有怪兽,这里天数在同一天的条件有两个:1.在当前攻击次数下最大得攻击力比从一个怪兽开始到现在最大得要大于等于2.不要超过n
代码:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 2e5 + ;
int a[N],b[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)b[i]=;
int ma_x =;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int m;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int p,s;
scanf("%d%d",&p,&s);
// mi_n = max(mi_n,p);
b[s]=max(b[s],p);
}
b[n+]=;
for(int i=n-;i>=;i--)
b[i]=max(b[i],b[i+]);
//cout <<"gehgb"<<endl;
int pos = ;
int ans = ;
while(pos<=n)
{
int cnt = pos;
int maxx = a[cnt];
while(cnt<=n&&b[cnt-pos+]>=maxx)
{
cnt++;
//cout<<a[cnt] <<"egrew"<<b[cnt-pos+1]<<endl;
maxx = max(maxx,a[cnt]);
}
if(cnt == pos)
{ ans=-;
break;
}
ans++;
pos =cnt;
}
printf("%d\n",ans);
}
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题
题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
随机推荐
- 计数器+打卡+习惯+目标APP推荐
目录 一.计数器类APP推荐 1.1. Thing Counter - Google Play 上的应用 1.2. Counter - Apps on Google Play 1.3. Counter ...
- selenium3.0不兼容火狐的解决方案
当直接调用火狐出现不兼容错误时,如何解决? 详看Message中提示:Expected browser binary location,but unable to find binary in def ...
- layuiAdmin (单页版)常见问题与解决方案
最近项目开发中用到了layuiAdmin的单页版进行开发,期间遇到一些问题,在此总结一二: 单页版缓存问题 由于单页面版本的视图文件和静态资源模块都是动态加载的,所以可能存在浏览器的本地缓存问题,因此 ...
- springboot和solr结合测试使用
首先新建springboot项目 新建webapp目录 springboot没有webapp目录——手动添加 web.xml <?xml version="1.0" enco ...
- [学习笔记] 在Eclipse中添加用户库 Add User Libraries ,在项目中引用用户库
如果还没有安装Eclipse, 则请参考前文: [学习笔记] 下载.安装.启动 Eclipse(OEPE) 添加用户库 本文主要介绍在项目中直接使用第三方库的情况.就是把第三方的jar文件直接放到某 ...
- Spark简介 --大数据
一.Spark是什么? 快速且通用的集群计算平台 二.Spark的特点: 快速:Spark扩充流行的Mapreduce计算模型,是基于内存的计算 通用:Spark的设计容纳了其它分布式系统拥有的功能, ...
- Time & Space Complexity
Quick Sort: Time complexity: best case O(n*lgn), worst case O(n^2) Space complexity: Best case O(lgn ...
- go 结构的方法总结
方法可以与命名类型或命名类型的指针关联. 刚刚看到的两个 Abs 方法.一个是在 *Vertex 指针类型上,而另一个在 MyFloat 值类型上. 有两个原因需要使用指针接收者.首先避免在每个方法调 ...
- 使用Duilib开发Windows软件(1)——HelloWorld
我使用的是网易版本: https://github.com/netease-im/NIM_Duilib_Framework 时间是2019-11-28,作者最新的提交如下图: 运行官方示例程序 下载完 ...
- Hibernate之关联关系(一对多)
今日分享hibernate框架的简单关联关系 一:关联关系简介 1.1 什么是关联关系 关联指的是类之间的引用关系.如果类A与类B关联,那么被引用的类B将被定义为类A的属性. 例如: class B{ ...