【CF1257D】Yet Another Monster Killing Problem【贪心】
题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过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【贪心】的更多相关文章
- 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) 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 ...
- D - Yet Another Monster Killing Problem
题目连接: https://codeforces.com/contest/1257/problem/D 题目大意: n个怪兽,m个英雄,每个怪兽有一定的能力值,每个英雄有一定的能力值和一定的耐力值.耐 ...
- 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 ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
- 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 ...
- 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 语言基础+高级_1-3-Java语言高级_06-File类与IO流_07 缓冲流_4_缓冲流的效率测试_复制文件
把之前文件复制的代码复制到这里 一个字节一个字节的读取,复制文件 byte数组的形式 缓冲流测试 数组缓冲
- delphi如何按照控件的左右顺序来遍历窗体中的每个控件 [问题点数:20 http://bbs.csdn.net/topics/380216822
delphi如何按照控件的左右顺序来遍历窗体中的每个控件delphi默认是按照控件添加进窗体的顺序来遍历的,有没有哪个属性能控制这个/?? 更多0分享到: 对我有用[0] 丢个板砖[0] 引用 | ...
- codeforces#1215E. Marbles(状压DP)
题目大意:给出一个由N个整数组成的序列,通过每次交换相邻的两个数,使这个序列的每个相同的数都相邻.求最小的交换次数. 比如给出序列:1 2 3 2 1 ,那么最终序列应该是 1 1 2 2 3 ,最小 ...
- Java反序列化漏洞整理
Fastjson 反序列化 CVE-- Fastjson 利用版本范围为 Fastjson 及之前的版本 Struts2 S2-, S2-, S2-, S2-, S2-, S2-, S2-, S2-, ...
- 20191105 《Spring5高级编程》笔记-第11章
第11章 任务调度 任务调度由三部分组成: 任务:需要在特定时间运行或定期运行的业务逻辑块: 触发器:指定任务应该执行的条件: 调度程序:根据来自触发器的信息执行任务: 11.2 Spring中的任务 ...
- linux command --- terminal common commands
switch to root : sudo su.su root.sudo -s switch to users : su god(user name) set root password : sud ...
- BZOJ 1875(DP+矩阵快速幂)
题面 传送门 分析 容易想到根据点来dp,设dp[i][j]表示到i点路径长度为j的方案数 状态转移方程为dp[i][k]=∑(i,j)∈Edp[j][k−1]" role="pr ...
- python 定义模块作用及分类
python把一个功能的模块归类,简单来说,模块是一个由Python代码组成的文件.模块可以定义函数,类和变量. 模块还可以包括可运行的代码. 1,python模块的作用 提高代码的方便维护 使用模块 ...
- wikioi 2144 分步二进制枚举+map记录
题目描写叙述 Description 有n个砝码,如今要称一个质量为m的物体,请问最少须要挑出几个砝码来称? 注意一个砝码最多仅仅能挑一次 输入描写叙述 Input Description 第一行两个 ...
- java反射, 不看你可别后悔
开发中, 难免遇到些私有的属性和方法, 就好比下面的实体一样, 我们该怎么获得她, 并玩弄于手掌呢? 我们先来个实体瞧瞧, 给你个对象你也new不了, hahaha- 单身wang public cl ...