【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 ...
随机推荐
- Linux_LDAP+NFS+autofs
目录 目录 前言 Ldap LDAPNFSautofs ServerPost 前言 LDAP+NFS+Autofs也是一种网络用户集中管理解决方案,相对于NIS+NFS+Autofs而言,有着更可靠的 ...
- 随机访问RandomAccessFile
public native long getFilePointer() throws IOException;//当前文件的指针位置是 import java.io.IOException; impo ...
- uni-app-v-else中不需要值
这个问题把我都高懵逼了 在vue中, 但是在uni-app中:v-else不需要值, 下面去掉值就Ok了
- sql exist 和not exist(转载)
exists : 强调的是是否返回结果集,不要求知道返回什么, 比如: select name from student where sex = 'm' and mark exists(select ...
- linux之shell脚本
1) 如何向脚本传递参数 ? ./script argument 例子: 显示文件名称脚本 ? 1 2 3 4 ./show.sh file1.txt cat show.sh #!/bin/bash ...
- levelDB Log-writer
分析完KV在内存中的存储,接下来就是操作日志.所有的写操作都必须先成功的append到操作日志中,然后再更新内存memtable.这样做有两个有点:1可以将随机的写IO变成append,极大的提高写磁 ...
- BitMap的原理和实现
相关概念 基础类型 在java中: byte -> 8 bits -->1字节 char -> 16 bit -->2字节 short -> 16 bits --> ...
- 埃及分数问题(带乐观估计函数的迭代加深搜索算法-IDA*)
#10022. 「一本通 1.3 练习 1」埃及分数 [题目描述] 在古埃及,人们使用单位分数的和(形如 $\dfrac{1}{a}$ 的,$a$ 是自然数)表示一切有理数.如:$\dfrac{ ...
- 3183 RMQ / 贪心(坑成。。)
题意:删去m个数,使剩下的数组成的数最小 题解 :贪心 , RMQ RMQ解法,建st表找,用rmq找最小值的下标,注意点 ,因为最小值是区间最右最小值,所以应该改成 <= 而不是< mi ...
- 纯css实现网上商城左侧垂直商品分类菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...