题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过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. OpenStack 多节点纳管 vCenter 5.5

    目录 目录 测试环境 Nova 配置OpenStack 纳管 vCenter 虚拟机 Glance 配置OpenStack 纳管 vCenter 镜像 Cinder 配置OpenStack 纳管 vC ...

  2. C++中的通用结构定义,及相应的序列化、反序列化接口

    一个通用的C++结构定义如下: typedef struct tagCommonStruct { long len; void* buff; }CommonStruct_st; 此接口对应的普通序列化 ...

  3. JQuery weui 中的Popup (弹出层:底部)

    //弹出层(从底部) <div id="bottomb" class="weui-popup__container popup-bottom"> & ...

  4. ceph部署-常用命令

    常用命令:1.ceph healthceph -s 2.ceph osd treeceph osd lspoolsceph osd pool [poolname] rbd pg_numceph osd ...

  5. Spring IoC,IoC原理

    一.IoC概念及原理 IOC的别名:依赖注入(DI) 2004年,Martin Fowler探讨了同一个问题,既然IOC是控制反转,那么到底是“哪些方面的控制被反转了呢?”,经过详细地分析和论证后,他 ...

  6. VBA中Let与Set的区别

    Let与Set的区别 1.在“类模块”中 Property Let 语句 在Class块中,是给普通变量进行赋值操作的Property,该种Property将不能在其前面使用Set,因而将不能用户对对 ...

  7. C# 委托 线程 窗体假死

    转载:http://www.cnblogs.com/smartls/archive/2011/04/08/2008981.html 异步调用是CLR为开发者提供的一种重要的编程手段,它也是构建高性能. ...

  8. RequireJS 入门(二)

    简介 如今最常用的JavaScript库之一是RequireJS.最近我参与的每个项目,都用到了RequireJS,或者是我向它们推荐了增加RequireJS.在这篇文章中,我将描述RequireJS ...

  9. Win10系统下插入耳机前面板无声后面板有声的处理

    问题描述: 当耳机插入后面板绿色口(注意:耳机扬声器为绿色口,红色为话筒麦克风:前后面板一样):可以听到声音,但是转到前面板插入后,无声音:调出声音面板发现声音可随音度波动 处理步骤: 1.保证插牢接 ...

  10. 一些关于C#发送邮件的代码

    1.命名空间 using System.Net.Mail; 2.创建一个MailMessage类的对象 MailMessage mail = new MailMessage(); MailMessag ...