洛谷 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 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_nr1,r2,⋯,rn (1\le r_i\le 1\ 000\ 000\ 0001≤ri≤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_mk1,k2,⋯,km (1\le k_j\le 1\ 000\ 000\ 0001≤kj≤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.
输入输出样例
7 3
5 6 4 3 6 2 3
3 2 5
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+;
}
洛谷 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
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(线段树)
洛谷题目传送门 \(O(n)\)的正解算法对我这个小蒟蒻真的还有点思维难度.洛谷题解里都讲得很好. 考试的时候一看到300000就直接去想各种带log的做法了,反正不怕T...... 我永远只会有最直 ...
- [洛谷P3444] [POI2006]ORK-Ploughing
洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...
- 洛谷P3435 [POI2006]OKR-Period of Words [KMP]
洛谷传送门,BZOJ传送门 OKR-Period of Words Description 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前缀, 当且仅当存在串B, ...
- 【题解】洛谷P3435 [POI2006] OKR-Periods of Words(KMP)
洛谷P3435:https://www.luogu.org/problemnew/show/P3435 思路 来自Kamijoulndex大佬的解释 先把题面转成人话: 对于给定串的每个前缀i,求最长 ...
- 洛谷 P3437 [POI2006]TET-Tetris 3D 解题报告
P3437 [POI2006]TET-Tetris 3D 题目描述 The authors of the game "Tetris" have decided to make a ...
- 洛谷.3437.[POI2006]TET-Tetris 3D(二维线段树)
题目链接 下落一个d*s的方块,则要在这个平面区域找一个最高的h' 更新整个平面区域的值为h+h' 对于本题,维护最大高度h和all 对于平面的x轴维护一棵线段树t1,每个t1的节点维护对应y轴的两棵 ...
随机推荐
- 【原创】websphere部署war包报错
应用程序在Tomcat上运行一切正常,但在websphere上部署时报以下错误:错误 500 处理请求时发生一个错误: /admin/upload.do 消息: WEB-INF/web.xml 详细错 ...
- Python 曲线拟合
#曲线拟合 fig = plt.figure() ax = fig.add_subplot(111)#将画布分割成1行1列,图像画在从左到右从上到下的第1块 ax.plot(Num,a,label=u ...
- Nginx域名配置文件bak
server { listen 80; server_name m.abd.com; rewrite ^(.*)$ https://$host$1 permanent; } server { list ...
- python登录注册改良版
#在执行本脚本的时候,需要先注册,否则会报字符串不匹配sum=3while True: #如果条件为真,则一直循环 print("先注册,在登录") print("1.注 ...
- caioj 1152 快速求模 (快速幂)
(1)开long long,不然中间结果会溢出 (2)注意一开始的初始化,保险一点. #include<cstdio> #include<cctype> #include< ...
- PNG文件结构分析
http://blog.163.com/iwait2012@126/blog/static/16947232820124411174877/ PNG文件结构分析 对于一个PNG文件来说,其文件头总是由 ...
- Extjs4.2 tooltip 提示宽度问题解决
在Extjs4.2 的tooltip 提示,宽度被限制在了40px,感觉非常别扭,是个BUG,解决的方法,在ext-all-debug.js或ext-all.js中,找到例如以下的代码: Ext.de ...
- Hadoop框架基础(五)
** Hadoop框架基础(五) 已经部署了Hadoop的完全分布式集群,我们知道NameNode节点的正常运行对于整个HDFS系统来说非常重要,如果NameNode宕掉了,那么整个HDFS就要整段垮 ...
- 美国人教你这样用Google,你真的会变特工
转自微博:黑客师: 用了这么久的谷歌,今天才发现. 第一篇 在搜索框上输入:“indexof/”inurl:lib 再按搜索你将进入许多图书馆,并且一定能下载自己喜欢的书籍. 在搜索框上输入:“ind ...
- SSRS 报表 报表迁移
数据拷贝下来以后在新的服务器上面还是进行原来的设置 点击报表服务器的连接查看报表服务器列表 这是给每个账户增加访问权限 在主界面点击文件夹设置,给每个角色分配操作报表的权限.,上面那个权限和这个权限都 ...