P3434 [POI2006]KRA-The Disks
题目描述
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 nnn and mmm ( 1≤n,m≤300 0001\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 nnn integers r1,r2,⋯,rnr_1,r_2,\cdots,r_nr1,r2,⋯,rn ( 1≤ri≤1 000 000 0001\le r_i\le 1\ 000\ 000\ 0001≤ri≤1 000 000 000 for 1≤i≤n1\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 mmm integers k1,k2,⋯,kmk_1,k_2,\cdots,k_mk1,k2,⋯,km ( 1≤kj≤1 000 000 0001\le k_j\le 1\ 000\ 000\ 0001≤kj≤1 000 000 000 for 1≤j≤m1\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 000 .
输入输出样例
7 3
5 6 4 3 6 2 3
3 2 5
2
Solution:
本题并不难。
显然每次一个物品从上往下掉,只会受到中途最小值的限制,于是我们直接用$f[i]$记录$1$到第$i$层之间的最小值。
然后每次放入一个物品,从最底层往上找,找到当前物品刚好不会被限制的层数,更新最底层的位置,每次都这样往上扫,若层数已经为$0$了就输出无解,否则输出最后的层数就好了。
代码:
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=;
int n,m,f[N],x,ans; il int gi(){
int a=;char x=getchar();
while(x<''||x>'')x=getchar();
while(x>=''&&x<='')a=(a<<)+(a<<)+x-,x=getchar();
return a;
} int main(){
n=gi(),m=gi();
ans=n+;f[]=0x7fffffff;
For(i,,n) x=gi(),f[i]=min(f[i-],x);
while(m--){
x=gi();
while(ans--){
if(f[ans]<x)continue;
break;
}
if(ans<=)puts(""),exit();
}
cout<<ans;
return ;
}
P3434 [POI2006]KRA-The Disks的更多相关文章
- 洛谷P3434 [POI2006]KRA-The Disks
P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...
- 洛谷 P3434 [POI2006]KRA-The Disks
P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...
- 洛谷 P3434 [POI2006]KRA-The Disks 贪心
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输出样例 输出样例 说明 思路 AC代码 题面 题目链接 P3434 [POI2006]KRA-The Disks 题目 ...
- 洛谷P3434 [POI2006]KRA-The Disks [模拟]
题目传送门 KRA 题目描述 For his birthday present little Johnny has received from his parents a new plaything ...
- 洛谷P3434 [POI2006]KRA-The Disks(线段树)
洛谷题目传送门 \(O(n)\)的正解算法对我这个小蒟蒻真的还有点思维难度.洛谷题解里都讲得很好. 考试的时候一看到300000就直接去想各种带log的做法了,反正不怕T...... 我永远只会有最直 ...
- BZOJ1510: [POI2006]Kra-The Disks
1510: [POI2006]Kra-The Disks Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 265 Solved: 157[Submit][ ...
- bzoj 1510 [POI2006]Kra-The Disks 二分
1510: [POI2006]Kra-The Disks Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 466 Solved: 272[Submit][ ...
- BZOJ1510 POI2006 Kra-The Disks 【模拟】
BZOJ1510 POI2006 Kra-The Disks LINK 还是粘题面吧,但是图就算了 Description Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一 ...
- 模拟 - BZOJ 1510 [POI2006] Kra-The Disks
BZOJ 1510 [POI2006] Kra-The Disks 描述 Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...
随机推荐
- npm 如何提升最新版本
首先我们查看一下npm当前版本,打开cmd 运行命令: npm -v 如果不是最新版本,运行一下代码即可. npm install -g npm 这样npm就更新到最新版本了. 如果想更新到指定版本, ...
- scala成长之路(2)对象和类
scala提供了一种特殊的定义单例的方法:object关键字 scala> object Shabi{ | val age = 0 | val name = "shabi" ...
- Table被web编程弃用的原因
Table要比其它html标记占更多的字节. (延迟下载时间,占用服务器更多的流量资源.)Tablle会阻挡浏览器渲染引擎的渲染顺序. (会延迟页面的生成速度,让用户等待更久的时间.)Table里显示 ...
- Jupyter Notebook里面使用Matplotlib画图 图表中文乱码问题
可查看以下链接: https://blog.csdn.net/ccblogger/article/details/79613335
- (数据科学学习手札33)基于Python的网络数据采集实战(1)
一.简介 前面两篇文章我们围绕利用Python进行网络数据采集铺垫了很多内容,但光说不练是不行的,于是乎,本篇就将基于笔者最近的一项数据需求进行一次网络数据采集的实战: 二.网易财经股票数据爬虫实战 ...
- Win10正式版激活
参考:https://jingyan.baidu.com/article/47a29f2457af76c015239942.html https://jingyan.baidu.com/article ...
- 41-Individual authentication 模板
1-创建项目,进入vscode控制台,输出如下命令, uld表示指定mssqllocaldb E:\coding\netcore>dotnet new mvc -au Individual -u ...
- FIFO的使用场景
(1) 数据的缓冲.如模型图所示,如果数据的写入速率高,但间隔大,且会有突发;读出速率小,但相对均匀.则通过设置相应深度的FIFO,可以起到数据暂存的功能,且能够使后续处理流程平滑,避免前级突发时,后 ...
- 2007: [Noi2010]海拔
2007: [Noi2010]海拔 https://www.lydsy.com/JudgeOnline/problem.php?id=2007 分析: 平面图最小割. S在左下,T在右上,从S到T的一 ...
- 【问题记录】Linux Python等交互式输入回退键出现 ^H^H
执行:yum install readline readline-devel