题目描述

For his birthday present little Johnny has received from his parents a new plaything which consists of a tube and a set of disks. The aforementioned tube is of unusual shape. Namely, it is made of a certain number of cylinders (of equal height) with apertures of different diameters carved coaxially through them. The tube is closed at the bottom, open at the top. An exemplary tube consisting of cylinders whose apertures have the diameters: 5cm, 6cm, 4cm, 3cm, 6cm, 2cm and 3cm is presented in the image below.

The disks in Johnny's plaything are cylinders of different diameters and height equal to those forming the tube.

Johnny has invented a following game: having a certain set of disks at his disposal, he seeks to find what depth the last of them would stop at, assuming that they are being thrown into the centre of the tube. If, for instance, we were to throw disks of consecutive diameters: 3cm, 2cm and 5cm, we would obtain the following situation:

As you can see, upon being thrown in, every disk falls until it gets stuck (which means that it lies atop a cylinder, aperture of which has a diameter smaller than the diameter of the disk) or it is stopped by an obstacle: the bottom of the tube or another disk, which has already stopped.

The game being difficult, Johnny constantly asks his parents for help. As Johnny's parents do not like such intellectual games, they have asked you - an acquaintance of theirs and a programmer - to write a programme which will provide them with answers to Johnny's questions.

TaskWrite a programme which:

reads the description of the tube and the disks which Johnny will throw into it from the standard input,computes the depth which the last disk thrown by Johnny stops at,writes the outcome to the standard output.

一个框,告诉你每一层的宽度。

向下丢给定宽度的木块。

木块会停在卡住他的那一层之上,异或是已经存在的木块之上。

询问丢的最后一个木块停在第几层。

输入输出格式

输入格式:

The first line of the standard input contains two integers nn and mm (1\le n,m\le 300\ 0001≤n,m≤300 000) separated by a single space and denoting the height of Johnny's tube (the number of cylinders it comprises) and the number of disks Johnny intends to throw into it, respectively. The second line of the standard input contains nn integers r_1,r_2,\cdots,r_nr​1​​,r​2​​,⋯,r​n​​ (1\le r_i\le 1\ 000\ 000\ 0001≤r​i​​≤1 000 000 000 for 1\le i\le n1≤i≤n) separated by single spaces and denoting the diameters of the apertures carved through the consecutive cylinders (in top-down order), which the tube consists of. The third line contains mm integers k_1,k_2,\cdots,k_mk​1​​,k​2​​,⋯,k​m​​ (1\le k_j\le 1\ 000\ 000\ 0001≤k​j​​≤1 000 000 000 for 1\le j\le m1≤j≤m) separated by single spaces and denoting the diameters of consecutive disks which Johnny intends to throw into the tube.

输出格式:

The first and only line of the standard output should contain a single integer denoting the depth which the last disk stops at. Should the disk not fall into the tube at all, the answer should be 00.

输入输出样例

输入样例#1:

7 3
5 6 4 3 6 2 3
3 2 5
输出样例#1:

2
思路:先预处理出通洞上方最窄的地方,然后模拟。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 300100
using namespace std;
int n,m,deep;
int val[MAXN],bns[MAXN],cost[MAXN];
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&val[i]);
for(int i=;i<=m;i++)
scanf("%d",&cost[i]);
bns[]=val[];
for(int i=;i<=n;i++)
if(bns[i-]<val[i]) bns[i]=bns[i-];
else bns[i]=val[i];
deep=n;
for(int i=;i<=m;i++){
while(bns[deep]<cost[i]) deep--;
deep--;
if(deep==){
cout<<"";
return ;
}
}
cout<<deep+;
}
 

最新文章

  1. JS核心系列:理解 new 的运行机制
  2. wcf DataTable作为返回类型
  3. 一点惊喜 --- alert()函数
  4. centos7 升级内核到最新版本
  5. submit 后台运行代码
  6. Android ThreadUtil 线程公共类,判断是否在主线程/ 子线程执行 相关操作
  7. Windows下虚拟机安装Mac OS X ----- VM12安装Mac OS X 10.11
  8. 从输入 URL 到页面加载完成的过程中都发生了什么事情?
  9. 【HDOJ】2255 奔小康赚大钱
  10. yii2安装与初始化-Yii2学习笔记(一)
  11. DOTween 模仿NGUI Tween
  12. jquery.qrcode二维码插件生成彩色二维码
  13. 开源搜索引擎Iveely 0.8.0
  14. 动态加载css方法实现和深入解析
  15. JavaScript对象类型之简单介绍
  16. Shell命令-文件及目录操作之pwd、rm
  17. nginx+keepalived高可用web负载均衡
  18. iOS - 高德地图步行线路规划多点多条线路
  19. DML和索引内部结构变化
  20. Study 6 —— while循环

热门文章

  1. NEC芯片特别说明
  2. SQL之子查询
  3. python中的json
  4. 优动漫PAINT-朱槿花的画法
  5. HDU-5693 D Game 动态规划 两次动规
  6. 基础命令:chown
  7. 将页面的内容导出使用html2canvas+jsPDF
  8. 紫书 习题8-19 UVa 1312 (枚举技巧)
  9. iOS基础UI控件介绍-Swift版
  10. 网页里如何使用js禁用F12事件