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 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...
随机推荐
- 一道SQL面试题——表行列数据转换(表转置)
SQL语句如下: select country, sum(case when type='A' then money end) as A, sum(case when type='B' then mo ...
- Yaf学习(一)----Linux安装Yaf
1.简介 Yaf,全称 Yet Another Framework,是一个高性能的PHP开发框架,采用PHP扩展实现(c语言).Blablablabla....... 2.环境 2.1 虚拟机 虚拟机 ...
- 廖老师的Python教程——安装Python
因为Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上.在Windows上写Python程序,放到Linux上也是能够运行的. 要开始学习Python编程,首先 ...
- python面向对象-多继承区别
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' 构造方法继承策略: 在python2中,经典类是按照深度优先继承构造方法的:新式类是按照广度优先 ...
- jmeter结合autoit操作windows程序
需求: 模拟操作下图软件的控件,如拨号和挂机. 1. 下载安装好autoit后,打开finder tool,使用查找工具定位到要模拟操作的控件上,如图: 2.在finder tool中的control ...
- 「暑期训练」「Brute Force」 Far Relative’s Problem (CFR343D2B)
题意 之后补 分析 我哭了,强行增加自己的思考复杂度...明明一道尬写的题- -(往区间贪心方向想了 其实完全没必要,注意到只有366天,直接穷举判断即可. 代码 #include <bits/ ...
- 【个人训练】(POJ1276)Cash Machine
最近的很多题解应该都是dp相关的了,emmm因为dp对我而言思考难度比较大,那么为了理顺自己的思路当然只能通过写blog整理了.愿我能成功搞定dp这个大关!(至少中等难度的dp要能够解决啊o(TヘTo ...
- 手动监控Windows端口
转载自http://blog.51cto.com/ywzhou/1579917 1.监控端口的几个主要Keys: net.tcp.listen[port] Checks if this port ...
- 一款代码高亮插件 -- SyntaxHighlighter
SyntaxHighlighter 是当前用得最多的一款代码高亮插件,包括本博客也用到了该插件来显示代码,大家可以看到效果了.只不过这是针对WordPress的一款代码高亮插件,而今天我要给大家介绍的 ...
- LAXCUS对数据存储的优化
LAXCUS兼容行存储(NSM)和列存储(DSM)两种数据模型,实现了混合存储.同时在分布环境里,做到将数据的分发和备份自动处理,这样就不再需要人工干预了. 行存储,为了兼容广大用户对 ...