题意:

有口井,往里扔盘子,最多扔多少个

n<=5e5, 1s

思路:

如果比较高的地方井口比较小,那么下面的再大也没有用,只需要维护一个单调减的数组然后O(n+m)模拟即可

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int a[maxn];
int b[maxn];
int n,m;
int main(){ int tmp = inf;
scanf("%d %d", &n,&m);
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
tmp = min(tmp, a[i]);
a[i] = min(tmp, a[i]);
}
int ans = ;
int p = n;
for(int i = ; i <= m; i++){
int x;
scanf("%d", &x);
while(p>=&&a[p]<x){
p--;
}
if(p){p--;ans++;} }
printf("%d",ans);
return ; }

51Nod 1279 扔盘子 (思维+模拟)的更多相关文章

  1. 51Nod 1279:扔盘子(二分||单调栈)

    1279 扔盘子 1.0 秒 131,072.0 KB 5 分 1级题 有一口井,井的高度为N,每隔1个单位它的宽度有变化.现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住( ...

  2. 51Nod-1279 扔盘子

    51Nod:  http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279 1279 扔盘子 题目来源: Codility 基 ...

  3. 51nod 1279 单调栈

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279 1279 扔盘子 题目来源: Codility 基准时间限制:1 ...

  4. 51nod 扔盘子

    题目传送门 这道题一开始写了n方的算法 果不其然 它T了 所以就想想o(n)的算法 写不出来 就像sbzhq学习了一下 这道题啊 要维护一下从深度1到n每一段的最小值以及他的位置 然后就暴力搞一搞就o ...

  5. CF--思维练习--CodeForces - 216C - Hiring Staff (思维+模拟)

    ACM思维题训练集合 A new Berland businessman Vitaly is going to open a household appliances' store. All he's ...

  6. 思维+模拟--POJ 1013 Counterfeit Dollar

    Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver d ...

  7. C. Okabe and Boxes 思维 模拟 or 线段树

    C. Okabe and Boxes 这个题目是一个有点思维的模拟,当时没有想到, 思维就是这个栈的排序这里,因为每次直接排序肯定会t的,所以不可以这么写,那怎么表示排序呢? 就是直接把栈清空,如果栈 ...

  8. Codeforces Round #706 (Div. 2)B. Max and Mex __ 思维, 模拟

    传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 ...

  9. Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维

    题意:博弈题面  给出一个数字序列 (>=11)  有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手  数字序列一定是奇 ...

随机推荐

  1. 关闭Win10 445端口

    这次勒索病毒利用了NSA黑客工具包中的“永恒之蓝”0day漏洞,通过电脑445端口(文件共享<普通用户基本用不到这个端口,可以关闭>)在内网进行蠕虫式感染传播,为了防止内网感染,建议用户关 ...

  2. 7个效果震憾的HTML5应用组件

    在HTML5的世界里,任何文本.图像都可以变得令人难以想象,很多HTML5应用也都已经随着浏览器的升级而变得运行飞速,而且兼容性也越来越好.下面为大家介绍7款效果震憾的HTML5应用组件,HTML5是 ...

  3. echart两组柱状图对比时,不同类型根据各类型的最大值为基准进行展示

    项目中遇到的问题:因为数据太小,箭头的地方展示不出来,这时的两组对比数据是根据一个最大值为基准进行渲染的.但我们想实现不同类型的对比根据不同的基准值渲染. 理想效果如下图: 实现代码: option ...

  4. Neo4j集群容器化部署

    集群基本配置(示例) core servers: 10.110.10.11, 10.110.10.12, 10.110.10.13read replicas: 10.110.10.14, 10.110 ...

  5. Epplus Excel 导入 MSSQL 数据库

    效果: 下载EXE     源码

  6. 【UEFI】---关于BIOS,EIST和PState&CState和CPU主频变化得关系

    Intel处理器都支持Turbo和EIST,且一般情况下,各家厂商在BIOS中都会设置EIST和PState的开关,那么这些开关与CPU的频率的关系是什么呢?今天对此做个总结: 按照国际惯例,本次梳理 ...

  7. Scrapy定制命令开启爬虫

    一.单爬虫运行 每次运行scrapy都要在终端输入命令太麻烦了 在项目的目录下创建manager.py(任意名称) from scrapy.cmdline import execute if __na ...

  8. 「 从0到1学习微服务SpringCloud 」08 构建消息驱动微服务的框架 Spring Cloud Stream

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」01 一起来学呀! 「 从0到1学习微服务SpringCloud 」02 Eureka服务注册与发现 「 从0到1学习微服务S ...

  9. SpringBoot配置嵌入式Servlet容器

    1).如何定制和修改Servlet容器的相关配置: 1.修改和server有关的配置(ServerProperties[也是EmbeddedServletContainerCustomizer]): ...

  10. Django中model的class Meta

    Class Meta 作用:使用内部类来提供一些metadata,以下列举一些常用的meta:1,abstract:如下段代码所示,将abstract设置为True后,CommonInfo无法作为一个 ...