题目传送门

KRA

题目描述

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 n and m ( 1≤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 integersr1​,r2​,⋯,rn​ ( 1≤ri​≤1 000 000 000 1≤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 integersk1​,k2​,⋯,km​ ( 1≤kj​≤1 000 000 000 for 1≤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 0 .

输入输出样例

输入样例#1:

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

2


  分析:

  今天考试遇到的题,实际上还是比较水的。(洛谷上的标签居然还是蓝题。。。orz)

  只需要模拟就可以了。可以得知到,如果上面有一根较窄的管子,那么下面比它宽的管子实际上就都并没有什么用处,所以可以从第一根管子开始将后面的管子宽度调整,然后每放一个盘子下去就从后往前遍历把它放在第一根比它宽的管子处,记该处为pos,然后可以直接把n变成pos-1,进行优化(显而易见的,盘子卡在那个地方后下面的管子都不管用了)。复杂度比较玄学,但是很显然是没有问题的,近似于O(n)。

  Code:

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+;
int n,m,r[N],a[N];
inline int read()
{
char ch=getchar();int num=;bool flag=false;
while(ch<''||ch>''){if(ch=='-')flag=true;ch=getchar();}
while(ch>=''&&ch<=''){num=num*+ch-'';ch=getchar();}
return flag?-num:num;
}
inline int find(int x)
{
for(int i=n;i>=;i--){
if(r[i]>=x)return i;}
return ;
}
int main()
{
n=read();m=read();int pos;
for(int i=;i<=n;i++)r[i]=read();
for(int i=;i<=m;i++)a[i]=read();
for(int i=;i<=n;i++){
if(r[i]>r[i-])r[i]=r[i-];}
for(int i=;i<=m;i++){
pos=find(a[i]);
if(pos==){printf("");return ;}
else n=pos-;}
printf("%d\n",pos);
return ;
}

洛谷P3434 [POI2006]KRA-The Disks [模拟]的更多相关文章

  1. 洛谷P3434 [POI2006]KRA-The Disks

    P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...

  2. 洛谷 P3434 [POI2006]KRA-The Disks

    P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...

  3. 洛谷 P3434 [POI2006]KRA-The Disks 贪心

    目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输出样例 输出样例 说明 思路 AC代码 题面 题目链接 P3434 [POI2006]KRA-The Disks 题目 ...

  4. 洛谷P3434 [POI2006]KRA-The Disks(线段树)

    洛谷题目传送门 \(O(n)\)的正解算法对我这个小蒟蒻真的还有点思维难度.洛谷题解里都讲得很好. 考试的时候一看到300000就直接去想各种带log的做法了,反正不怕T...... 我永远只会有最直 ...

  5. [洛谷P3444] [POI2006]ORK-Ploughing

    洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...

  6. 洛谷 P3695 CYaRon!语 题解 【模拟】【字符串】

    大模拟好啊! 万一远古计算机让我写个解释器还真是得爆零了呢. 题目背景 「千歌です」(我是千歌).「曜です」(我是曜).「ルビィです」(我是露比).「3人合わせて.We are CYaRon! よろし ...

  7. 洛谷P3435 [POI2006]OKR-Period of Words [KMP]

    洛谷传送门,BZOJ传送门 OKR-Period of Words Description 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前缀, 当且仅当存在串B, ...

  8. 【题解】洛谷P1065 [NOIP2006TG] 作业调度方案(模拟+阅读理解)

    次元传送门:洛谷P1065 思路 简单讲一下用到的数组含义 work 第i个工件已经做了几道工序 num 第i个工序的安排顺序 finnish 第i个工件每道工序的结束时间 need 第i个工件第j道 ...

  9. 【题解】洛谷P3435 [POI2006] OKR-Periods of Words(KMP)

    洛谷P3435:https://www.luogu.org/problemnew/show/P3435 思路 来自Kamijoulndex大佬的解释 先把题面转成人话: 对于给定串的每个前缀i,求最长 ...

随机推荐

  1. Spring 与 SpringMVC 容器父子关系引出的相应问题

    1)关系说明 spring 与 springmvc 父子关系:spring (父容器),springmvc (子容器) springmvc(子)--- 可调用 --> spring(父) 中的 ...

  2. yum源的使用

    yum通过仓库拉取,同时解决了依赖的问题.有仓库的都是通过社区来维护的,不同的发行版会有不同的社区来维护 此时就是客户端和服务器的关系的问题了,yum会依赖一个配置文件, yum 的理念是使用一个中心 ...

  3. 用Vue来实现图片上传多种方式

    没有业务场景的功能都是耍流氓,那么我们先来模拟一个需要实现的业务场景.假设我们要做一个后台系统添加商品的页面,有一些商品名称.信息等字段,还有需要上传商品轮播图的需求. 我们就以Vue.Element ...

  4. A .Gaby And Addition (Gym - 101466A + 字典树)

    题目链接:http://codeforces.com/gym/101466/problem/A 题目: 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 思路: ...

  5. Sublime删除项目删不掉?

    最近用sublime进行项目的开发,感觉懵逼的像个小白菜~~ 今天遇到的问题可是一个超级白痴的问题,sublime的空白项目文件夹怎么都删不掉,我的傻逼操作是:选中文件--->Delete--- ...

  6. 【译】第三篇 SQL Server代理警报和操作员

    本篇文章是SQL Server代理系列的第三篇,详细内容请参考原文. 正如这一系列的上一篇所述,SQL Server代理作业是由一系列的作业步骤组成,每个步骤由一个独立的类型去执行,除了步骤中执行的工 ...

  7. 搭建自己的PHP框架心得——转载

    原文:http://www.cnblogs.com/zhenbianshu/p/5331165.html 前言 说到写PHP的MVC框架,大家想到的第一个词--“造轮子”,是的,一个还没有深厚功力的程 ...

  8. python简单爬虫一

    简单的说,爬虫的意思就是根据url访问请求,然后对返回的数据进行提取,获取对自己有用的信息.然后我们可以将这些有用的信息保存到数据库或者保存到文件中.如果我们手工一个一个访问提取非常慢,所以我们需要编 ...

  9. bootstrap分页查询传递中文参数到后台(get方式提交)

    <!--分页 --> <div style="width: 380px; margin: 0 auto; margin-top: 50px;"> <u ...

  10. Thinkphp的SQL查询方式

    一.普通查询方式 a.字符串$arr=$m->where("sex=0 and username='gege'")->find();b.数组$data['sex']=0 ...