51Nod 1279 扔盘子 (思维+模拟)
题意:
有口井,往里扔盘子,最多扔多少个

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 扔盘子 (思维+模拟)的更多相关文章
- 51Nod 1279:扔盘子(二分||单调栈)
1279 扔盘子 1.0 秒 131,072.0 KB 5 分 1级题 有一口井,井的高度为N,每隔1个单位它的宽度有变化.现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住( ...
- 51Nod-1279 扔盘子
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279 1279 扔盘子 题目来源: Codility 基 ...
- 51nod 1279 单调栈
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1279 1279 扔盘子 题目来源: Codility 基准时间限制:1 ...
- 51nod 扔盘子
题目传送门 这道题一开始写了n方的算法 果不其然 它T了 所以就想想o(n)的算法 写不出来 就像sbzhq学习了一下 这道题啊 要维护一下从深度1到n每一段的最小值以及他的位置 然后就暴力搞一搞就o ...
- CF--思维练习--CodeForces - 216C - Hiring Staff (思维+模拟)
ACM思维题训练集合 A new Berland businessman Vitaly is going to open a household appliances' store. All he's ...
- 思维+模拟--POJ 1013 Counterfeit Dollar
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver d ...
- C. Okabe and Boxes 思维 模拟 or 线段树
C. Okabe and Boxes 这个题目是一个有点思维的模拟,当时没有想到, 思维就是这个栈的排序这里,因为每次直接排序肯定会t的,所以不可以这么写,那怎么表示排序呢? 就是直接把栈清空,如果栈 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
题意:博弈题面 给出一个数字序列 (>=11) 有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
随机推荐
- 基于GPS北斗卫星授时系统和NTP网络授时服务器的设计与开发
基于GPS北斗卫星授时系统和NTP网络授时服务器的设计与开发 安徽京准科技提供@请勿转载@@ 更多资料请参考——ahjzsz.com 天文观测设备对于控制系统的时间准确度有严格要求.为此,采用搭建高精 ...
- 写 Java 这么久了,来编译个 JDK 玩玩儿吧
你每天写的 Java 代码都需要 JDK 的支持,都要跑在 JVM 上,难道你就不好奇 JDK 长什么样子吗.好奇,就来编译并实现一个自己的 JDK 吧. 本次编译环境 macOS 10.12,编译的 ...
- 开箱即用!使用Rancher 2.3 启用Istio初体验
本文来自Rancher Labs Rancher的理念是Run Kubernetes Everywhere,Rancher 2.3中许多重大更新,让这一理念的实现又向前一步. 其中,最重要的两个特性是 ...
- Spring中常见的设计模式——模板模式
一.模板模式的应用场景 模板模式又叫模板方法模式(Template Method Pattern),指定义一个算法的骨架,并允许自雷为一个或者多个步骤提供实现.模板模式使得子类可以在不改变算法结果的情 ...
- SpringBoot基础架构篇3(Redis)
show me the code and talk to me,做的出来更要说的明白 我是布尔bl,你的支持是我分享的动力! 1 引入 数据库达到瓶颈,有什么解决方法. Redis 可以很好解决这个问 ...
- 流程控制-物流费用计算(嵌套if)
题目描述 快递公司规定,如果物品体积超过2.5立方米,不允许快递.如果重量超过40kg,不允许快递.快递收费价格为: 小于等于1kg,一口价10块钱: 大于1kg,小于等于5kg,10块钱的基础上,每 ...
- jdk1.7扩容时,不论是否有链表,并发都可能出现循环链表
扩容时使用transfertransfer不同于put时的判断hash冲突,直接使用头插法,如果没有冲突,则next为null.如下:e.next = newTable[i];newTable[i] ...
- 【Java基础总结】网络编程
网络编程 InetAddress tcp udp
- Thinkpad S440 I/O接口配置
HDMI 视频接口 SS USB3.0接口 电源接口 音频接口 网络接口 没有com口可以用USB口,然后安装一个USB转com口的驱动.
- Jetbrains CLion 安装及配置详解
# Hi 今天呢就给大家推荐一个高大上 强大智能的 C/C++语言编辑器.ta的名字叫-- Jetbrains CLion (呃,说好了不用标题字呢) 这个编辑器呢主要支持C和C ++,包括现代C + ...