题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过si个怪物,每个勇士只能打能力值≤pi的怪物,问最少多少天打完所有怪物

题解:贪心,每天尽可能多的去打怪,那么存一个对于长度为i的怪物可以用的最大的能力值是多少,每天枚举长度,尽可能长的去打怪即可

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int T,n,m,ans;
int a[],mx[];
struct node
{
int p,s;
}b[];
bool cmp(const node &T1,const node &T2){return T1.s>T2.s;}
int main()
{
scanf("%d",&T);
while(T--)
{
for(int i=;i<=n;i++)mx[i]=;
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
scanf("%d",&m);
for(int i=;i<=m;i++)scanf("%d%d",&b[i].p,&b[i].s);
sort(b+,b++m,cmp);
int j=,t=;
for(int i=n;i>;i--)
{
while(j<=m && b[j].s>=i)
{
t=max(t,b[j].p);
j++;
}
mx[i]=t;
}
ans=;j=;t=;
for(int i=;i<=n;i++)
{
t=max(t,a[i]);
if(t>mx[j])
{
//printf("%d %d %d %d\n",i,j,a[i],mx[j]);
if(j==){ans=-;break;}
ans++;j=;i--;t=;
}
else j++;
}
if(ans>-)ans++;
//for(int i=1;i<=n;i++)printf("%d ",mx[i]);
printf("%d\n",ans);
}
return ;
}

【CF1257D】Yet Another Monster Killing Problem【贪心】的更多相关文章

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

  2. Educational Codeforces Round 76 (Rated for Div. 2) D. Yet Another Monster Killing Problem

    You play a computer game. In this game, you lead a party of mm heroes, and you have to clear a dunge ...

  3. D - Yet Another Monster Killing Problem

    题目连接: https://codeforces.com/contest/1257/problem/D 题目大意: n个怪兽,m个英雄,每个怪兽有一定的能力值,每个英雄有一定的能力值和一定的耐力值.耐 ...

  4. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. codeforces 442B B. Andrey and Problem(贪心)

    题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  8. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心

    D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...

  9. Codeforces Round #296 (Div. 1) B. Clique Problem 贪心

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

随机推荐

  1. PANIC: Missing emulator engine program for ‘x86’ CPU.

    参考链接:https://zhidao.baidu.com/question/652153765084187325.html 解决方案:看图最上面路径,进入你的文件夹下,把红文件夹 ( 1 ) 中的所 ...

  2. UI自动化之三种等待

    UI自动化中常用三种等待 目录 1.强制等待 2.隐式等待 3.显示等待 1.强制等待 执行到某一条语句后,然后sleep(3),等待3秒后,才会继续执行后面的语句 2.隐式等待 隐式等待只需要声明一 ...

  3. 解决旋转屏幕闪退在androidManifest.template.xml里,activity项添加:

     解决旋转屏幕闪退在androidManifest.template.xml里,activity项添加:android:configChanges="orientation|keyboard ...

  4. Mac013--Docker安装

    一.Docker安装教程 参考:http://www.runoob.com/docker/macos-docker-install.html 可应用brew命令安装,也可自定义下载安装. 应用brew ...

  5. Mac入门--如何使用brew安装多个PHP版本

    一 安装7.1 1. 安装PHP7.1 brew install php@7.1 2. 修改配置 php-fpm.conf,一般在/usr/local/etc/php下(如果php-fpm.conf中 ...

  6. Spring MVC配置文件

    都说开发Spring Web程序的配置文件很繁琐,所以就写了一篇配置博客, 首先是pom.xml文件 <project xmlns="http://maven.apache.org/P ...

  7. 前端 CSS的选择器 伪类选择器

    伪类选择器 常用的几种伪类选择器. 伪类选择器一般会用在超链接a标签中 没有访问的超链接a标签样式: a:link { color: blue; } <!DOCTYPE html> < ...

  8. NFS实现文件共享

    NFS(Network Files System)即网络文件系统,NFS文件系统协议允许网络中的主机通过TCP/IP协议进行资源共享,NFS客户端可以像使用本地资源一样读写远端NFS服务端的资料,需要 ...

  9. Sentinel之熔断降级

    除了流量控制以外,对调用链路中不稳定的资源进行熔断降级也是保障高可用的重要措施之一.由于调用关系的复杂性,如果调用链路中的某个资源不稳定,最终会导致请求发生堆积.Sentinel 熔断降级会在调用链路 ...

  10. mysql 小数位

    1    select convert(t/100,decimal(15,2)) as a from user (1) convert() 一.在mysql操作中我们经常需要对数据进行类型转换.此时我 ...