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. hana客户端工具

    SAP HANA可视化客户端工具是C/S模式的,远程访问使用,都不是太方便,目前有一款基于WEB的可视化工具TreeSoft,通过浏览器就可以访问使用了,并且可以同时管理.维护.监控SAP HANA等 ...

  2. 《C语言程序设计》学习笔记(二)

    第八章 函数 函数的基本概念 定义:函数由函数名.参数和函数体组成. 函数定义的一般形式: 类型说明符 函数名(形式参数声明) { [说明与定义部分] 语句: } 说明: 1.类型说明符用来说明函数的 ...

  3. Echarts 图表的本地配置

    前言 Echarts是一个美观的可视化工具,但是很多朋友初次接触,不知道自己该怎么创建一个包含Echartst图表的本地HTML网页,本文将详细地介绍Echarts的使用流程. 使用流程步骤 共分为三 ...

  4. 【ARM-Linux开发】Wi-Fi 应用工具wpa_supplicant

    wpa_supplicant是一个跨平台的无线安全管理软件,这里需要用它来对无线网络进行配置,wpa_supplicant相关工具已经移植好,包含在我们提供的文件系统中. 配置无线网络 wpa_sup ...

  5. 不使用局部变量和for循环或其它循环打印出如m=19,n=2結果为2 4 8 16 16 8 4 2形式的串

    需求:不使用局部变量和for循环或其它循环打印形如:2 4 8 16 16 8 4 2 这样的串 代码MainTest.java package com.szp.study.javase.specia ...

  6. easyui loadFilter 使用

    $('#selectChannelForSignup_getBill').combobox({ url:'../channel/listAdvanceChannelPage', queryParams ...

  7. rest_framework之组件大长今

    功能导入快捷查询: from rest_framework import serializers # 序列化from rest_framework.routers import SimpleRoute ...

  8. 【leetcode算法-简单】28. 实现strStr

    [题目描述] 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如 ...

  9. Redis 常用命令学习二:字符串类型命令

    1.赋值与取值命令 127.0.0.1:6379> set foo helloredis OK 127.0.0.1:6379> get foo "helloredis" ...

  10. 烧脑!CMU、北大等合著论文真的找到了神经网络的全局最优解

    烧脑!CMU.北大等合著论文真的找到了神经网络的全局最优解 机器之心 ​ 已认证的官方帐号 811 人赞同了该文章 选自arXiv,作者:Simon S. Du.Jason D. Lee.Haochu ...