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的更多相关文章

  1. Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest

    Educational Codeforces Round 76 (Rated for Div. 2) E. The Contest(dp+线段树) 题目链接 题意: 给定3个人互不相同的多个数字,可以 ...

  2. Educational Codeforces Round 76 (Rated for Div. 2)E(dp||贪心||题解写法)

    题:https://codeforces.com/contest/1257/problem/E 题意:给定3个数组,可行操作:每个数都可以跳到另外俩个数组中去,实行多步操作后使三个数组拼接起来形成升序 ...

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

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

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

  6. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray 水题

    C. Dominated Subarray Let's call an array

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

  8. Educational Codeforces Round 76 (Rated for Div. 2) A. Two Rival Students 水题

    A. Two Rival Students There are

  9. Educational Codeforces Round 76 (Rated for Div. 2) D题

    题意: 给你n个关卡,每个关卡有一个怪物,怪物的攻击力为a[i],你有n个英雄,每个英雄有一个攻击力,和疲劳值,只要英雄的攻击力比怪物的高就算打过了,同时疲劳减一,一天只能出战一个英雄,一个英雄可以打 ...

随机推荐

  1. MMC.EXE应用程序错误 应用程序无法正常启动(0XC0000043)

    一.Windows+R 输入 regedit.exe ①打开注册表: HKEY_LOCAL_MACHINE“"SOFTWARE""Classes""C ...

  2. 字符串匹配算法---BF

    Brute-Force算法,简称BF算法,是一种简单朴素的模式匹配算法,常用语在一个主串string 内查找一个子串 pattern的出现位置. 核心思想: i 遍历主串string i 每自增一次, ...

  3. 【VS开发】【miscellaneous】 Windows下配置Git

    [转自]http://blog.csdn.net/exlsunshine/article/details/18939329 1.从git官网下载windows版本的git:http://git-scm ...

  4. go timer定时器 WaitGroup用法

    参考文章: timer定时器: https://www.cnblogs.com/oxspirt/p/7107312.html WaitGroup用法: https://studygolang.com/ ...

  5. poj2074(求直线的交点)

    题目链接:https://vjudge.net/problem/POJ-2074 题意:给定L1(Housing Line),L2(properity line),和一些L[i](obstructio ...

  6. ThreadLocal的坑--ThreadLocal跨线程传递问题

    1.父子线程间的传递问题 ThreadLocal的子类InheritableThreadLocal其实已经帮我们处理好了,通过这个组件可以实现父子线程之间的数据传递,在子线程中能够父线程中的Threa ...

  7. LIUNX随堂学习-1 用户及查看信息

    1.useradd   #创建用户             例如:useradd ljj     创建一个名为ljj的用户 2.userdel -r    #删除用户         例如:userd ...

  8. ndarray笔记续

    数组的索引与切片 多维数组的索引 import numpy as np arr=np.arange(1,25).reshape(2,3,4) arr # 输出 array([[[ 1, 2, 3, 4 ...

  9. 【闭包】Pants On Fire

    Pants On Fire 题目描述 Donald and Mike are the leaders of the free world and haven’t yet (after half a y ...

  10. Ubuntu 搭建 配置 nfs服务器

    什么是NFS? NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NF ...