题意:

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

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. 从零开始学asyncio(上)

    这篇文章主要是介绍生成器和IO多路复用机制, 算是学习asyncio需要的预备知识. 这个系列还有另外两篇文章: 从零开始学asyncio(中) 从零开始学asyncio(下) 一. 简单爬虫实例 首 ...

  2. vim的常用指令(脑图)

    将正在编辑的文件另存新文件名   :w newfilename 在正在编辑的文件中,读取一个filename    :r filename 做了很多编辑工作,想还原成原来的文件内容   :e! 我在v ...

  3. word 发表博客

    发表博客大家可采用熟悉的word 编辑排版,然后发布博客.(这里我使用的是word 2013,其他版本大家可以自己测试) 使用word发布博客时,需要先配置一下: 1)单击文件---〉共享---〉发布 ...

  4. 通过例子进阶学习C++(五)计算2的1次方至2的64次方之和

    本文是通过例子学习C++的第五篇,通过这个例子可以快速入门c++相关的语法. 1.上篇回顾 在上一篇中,我们通过字符数组计算264次方: 通过例子进阶学习C++(四)计算2的64次方 带着这个问题:为 ...

  5. Java 利用Map集合计算一个字符串中每个字符出现的次数

    步骤分析 1.给出一串字符串,字符串中可以包含字母.数字.符号等等. 2.创建一个Map集合,key是字符串中的字符,value是字符的个数. 3.遍历字符串,获取每一个字符. 5.使用获取到的字符, ...

  6. 2019 ICCV、CVPR、ICLR之视频预测读书笔记

    2019 ICCV.CVPR.ICLR之视频预测读书笔记 作者 | 文永亮 学校 | 哈尔滨工业大学(深圳) 研究方向 | 视频预测.时空序列预测 ICCV 2019 CVP github地址:htt ...

  7. RSA 的加密 解密

    RSA加密解密类: package me.hao0.trace.order; import java.io.BufferedReader; import java.io.BufferedWriter; ...

  8. 2019 牛客国庆集训day1 2019 点分治

    题目链接:https://ac.nowcoder.com/acm/contest/1099/I 点分治,计算路径数的时候,先将每个点到根的距离模2019,计算的时候就可以O(n)求出数目,对于模201 ...

  9. 关于互信息(Mutual Information),我有些话要说

    两个随机变量的独立性表示两个变量X与Y是否有关系(贝叶斯可证),但是关系的强弱(mutual dependence)是无法表示的,为此我们引入了互信息. 其中 p(x,y) 是 X 和 Y 的联合概率 ...

  10. Oracle GoldenGate Best Practices: Active-Active Configuration with DML Auto CDR

    Executive Overview This document is an introduction to Oracle GoldenGate (DIPC remote agent)’s best ...