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. 异地协作,A地上传jar包到B地服务器上传速率慢

    在A地使用ftp服务器,再登录B地的目标服务器,使用ftp命令从ftp服务器下载文件,速度快点,下载带宽比上传带宽要大一点 https://blog.csdn.net/df0128/article/d ...

  2. Flutter easyrefresh示例 上拉加载+下拉刷新

    官方示例,简单改了下,实现功能为主. 代码如下: import 'dart:async'; import 'package:flutter/material.dart'; import 'packag ...

  3. CommMonitor8.0 串口过滤驱动 SDK DLL版本 C#/Delphi调用DEMO

    CommMonitor8.0 SDK DLL 版本,此版本是直接调用DLL. Delphi调用定义: constCommMOnitor8x = ‘CommMOnitor8x.dll’; typeTOn ...

  4. sed练习,一些sed常用方法

    1.复制/etc/rc.d/rc.local 文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#. sed -ri 's/^ +/#/g'  rc.loc ...

  5. OWASP TOP 10(OWASP十大应用安全风险)

    TOP1-注入 当不受信任的数据作为命令或查询的一部分发送到解释器时,会发生注入漏洞,例如SQL,NoSQL,OS,LDAP注入(轻量目录访问协议),xpath(XPath即为XML路径语言,它是一种 ...

  6. Feign【替换默认的feign client】

    说明: feign默认情况下使用的是JDK原始的URLConnection发送的HTTP请求,没有使用到连接池,但是对每个地址会保持长连接,即HTTP的persistence connection.我 ...

  7. S03_CH13_ZYNQ A9 TCP UART双核AMP例程

    S03_CH13_ZYNQ A9 TCP UART双核AMP例程 13.1概述 ZYNQ中存在两个独立的ARM核,在很多应用场景中往往只需使用其中的1个核心即可.然而,对于复杂的设计,例如多任务,并行 ...

  8. Intellij IDEA中启动多个微服务--开启Run Dashboard管理

    1.找到workspace.xml 2.添加配置 <option name="configurationTypes"> <set> <option v ...

  9. asp.net core-15.Individual authentication 模板

    在visual studio code执行dotnet new mvc --help 可以查看执行命令 visual studio code先创建一个mvc的项目 dotnet new mvc -au ...

  10. MySQL 子查询(二)

    接上篇文章,从这节起:MySQL 5.7 13.2.10.5 Row Subqueries 五.行子查询(ROW Subqueries) 标量子查询返回单个值,列子查询返回一个列的多个值.而行子查询是 ...