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 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...
随机推荐
- Co. - Apple - MacBook Pro 快捷键
Mac 键盘快捷键:https://support.apple.com/zh-cn/HT201236 从windows转到mac的童鞋,可能删除键是心中的一个痛,以前习惯一按delete什么都消失,其 ...
- [转]win7下修改C盘USERS文件下的名称
Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Co ...
- laydate js动态添加时间
$("#test2").click(function(){ var input=$('<input/>'); $("#test1").append( ...
- 13.4.3 鼠标与滚轮事件【JavaScript高级程序设计第三版】
鼠标事件是Web 开发中最常用的一类事件,毕竟鼠标还是最主要的定位设备.DOM3 级事件中定义了9 个鼠标事件,简介如下. click:在用户单击主鼠标按钮(一般是左边的按钮)或者按下回车键时触发.这 ...
- [转载]三小时学会Kubernetes:容器编排详细指南
原翻译by梁晓勇 原英文:Learn Kubernetes in Under 3 Hours: A Detailed Guide to Orchestrating Containers 我很奇怪,为什 ...
- Rmarkdown:输出html设置
在Rstudio中可自行更改主题样式 --- title: "题目" author: "name" date: "`r format(Sys.time ...
- Rmarkdown:输出pdf设置
输出pdf需要安装Ctex --- title: "first markdown" author: "name" date: "`r format(S ...
- P1396 营救(最小瓶颈路)
题目描述 “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!小明感动的热泪盈眶,开起了门…… 妈妈下班回家,街坊邻居说小明被一群陌生人强行押上了警车!妈妈丰富的经验告诉她小 ...
- shell重温---基础篇(参数传递&echo命令)
经过前两天的学习,关于shell的基础算是知道的一般般啦,最起码不算是小白了(纯属意淫).今天就来点干货哈. 首先是运行shell脚本时的参数传递.脚本内获取参数的格式为$n.n代表了一个数字,例 ...
- Delphi中ModalResult的使用
Delphi中ModalResult的功能非常实用. 在自己设计的Dialog界面中,选择相应的按钮,设置按钮的 ModalResult属性为mrOK .mrCancel 等.这样的设置,当按下该按钮 ...