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个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...
随机推荐
- html转图片网页截屏(三),puppeteer
puppeteer谷歌出品,是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome. 官方github地址:https://github ...
- GPU Skinning 结合 Instanced 高效实现大量单位动画
GPU Skinning 与 Instance 蒙皮动画 计算骨骼信息 蒙皮 GPU Skinning CPU Skinning 与 GPU Skinning 实现方式 Skinning 类型 优点 ...
- 给引入页面的js和css资源加上版本号,防止浏览器缓存资源
最近因为在做前端开发的相关工作,每次发布新版本以后,不到5分钟,测试童鞋一个接一个的抱怨说BUG根本就没有修改,这个时候你说的最多的话就是“清缓存!!清页面缓存!!你没有清缓存!!你清理了页面缓存就对 ...
- 日常工作问题解决:使用vmvare克隆centos6虚拟机造成无eth0的解决办法
目录 一.问题描述 样本虚拟机配置有两张网卡,eth0.eth1,使用vmvare克隆虚拟机后,复制的虚拟机,没有网卡eth0,eth1,而是有eth2.eth3,如下所示: 二.原因分析 复制系统中 ...
- C#学习笔记06--类/对象/访问修饰符/方法
编程思想 1.面向过程 面向过程是要把问题解决的过程分成有一定顺序的不同步骤, 然后按照步骤一步步的将问题解决. 2.面向对象 面向对象解决问题的思路是先分析问题中所涉及的对象, 然后 ...
- layer弹出层,结合art-template实现弹出编辑
模板 <!-- 模板 --> <script id="render-tpl" type="text/html"> <div cla ...
- sql server 2012 链接服务器不能链接sql server 2000的解决方案 ,
本数据源来自 https://www.kafan.cn/edu/922556.html 目的为了备忘 把原来的sql server 2005直接装成了2012,然后在建立链接服务器链接一台sql s ...
- REDIS scan与sunionstore合并多集合数据
实际业务场景: 现需求要将多个KEY的set集合数据合并到一个总集合中,思路:通过scan分批扫描满足条件的KEY,然后用sunionstore分批合并. 注意闭坑:此种解决方案只适用于待合并的集合K ...
- 纯java代码搭建ssm
参考: https://blog.csdn.net/Smile__1/article/details/103394460
- consul 初体验
consul server: 192.168.48.134: #!/bin/bash cd /data/server/consuls nohup /data/server/consuls/consul ...