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那么就是第一个赢 否则就是第二个人赢 第一个人先手 数字序列一定是奇 ...
随机推荐
- how to render html tag
使用autoescaping If autoescaping is turned on in the environment, all output will automatically be esc ...
- 从数组中取出n个不同的数组成子集 y 使 x = Σy
/** * 尝试获取arr子集 y 使 x=Σy * @param {Array} arr * @param {number} x * @param {Array} res */ f ...
- 1、纯python编写学生信息管理系统
1.效果图 2.python code: class studentSys(object): ''' _init_(self) 被称为类的构造函数或初始化方法, self 代表类的实例,self 在定 ...
- 小程序中button标签的open-type属性
open-type (微信开放能力):合法值中的其中之一: getUserInfo 说明:引导用户授权 而获取用户信息,可以从bindgetuserinfo回调中获取到用户信息 而按钮的bi ...
- NPOI读取Excel的数据
首先是给项目安装NPOI.DLL :Install-Package NPOI -Version 2.4.1 HttpPostedFile upLoadPostFile = FileUpload1.Po ...
- playbooks框架与子文件编写规范
Test Playbooks框架 详细目录testenv文件 主任务文件main.yml 任务入口文件deploy.yml Ansible连接playbooks需要添加ssh协议认证 ...
- Java中的equalsIgnoreCase()
在工作中偶然机会看到了equalsIgnoreCase()这个方法,相信大家和我一样equals()是再熟悉不过的了,但是对于equalsIgnoreCase()有点眼生(大神勿喷),所以写了这篇博客 ...
- flask模板 flask-bootstrap
1.模板 a.block块中继承前面block块的内容,需要添加{{super()}} b.macro 宏: 作用:在模板中定义函数(定义函数->注意添加()->可以使用from 模板 ...
- Java入门 - 面向对象 - 07.包(package)
原文地址:http://www.work100.net/training/java-package.html 更多教程:光束云 - 免费课程 包(package) 序号 文内章节 视频 1 概述 2 ...
- 机器学习环境配置系列三之Anaconda
1.下载Anaconda文件 进入anaconda的官网 选择对应的系统 选择希望下载的版本(本人下载的是Anaconda 5.3 For Linux Installer Python 3.7 ver ...