题目描述

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 .

输入输出样例

输入样例#1:

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

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的更多相关文章

  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 [模拟]

    题目传送门 KRA 题目描述 For his birthday present little Johnny has received from his parents a new plaything ...

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

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

  6. BZOJ1510: [POI2006]Kra-The Disks

    1510: [POI2006]Kra-The Disks Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 265  Solved: 157[Submit][ ...

  7. bzoj 1510 [POI2006]Kra-The Disks 二分

    1510: [POI2006]Kra-The Disks Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 466  Solved: 272[Submit][ ...

  8. BZOJ1510 POI2006 Kra-The Disks 【模拟】

    BZOJ1510 POI2006 Kra-The Disks LINK 还是粘题面吧,但是图就算了 Description Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一 ...

  9. 模拟 - BZOJ 1510 [POI2006] Kra-The Disks

    BZOJ 1510 [POI2006] Kra-The Disks 描述 Johnny 在生日时收到了一件特殊的礼物,这件礼物由一个奇形怪状的管子和一些盘子组成. 这个管子是由许多不同直径的圆筒(直径 ...

随机推荐

  1. (转)Windows安装和使用zookeeper

    (转)原地址https://www.cnblogs.com/shanyou/p/3221990.html 之前整理过一篇文章<zookeeper 分布式锁服务>,本文介绍的 Zookeep ...

  2. jquery validation remote进行唯一性验证时只使用自定义参数,不使用默认参数

    在使用validation进行唯一性验证时,想各个模块写一个统一的方法,相统一参数名称,但是remote方法会默认把对应的参数传过去 如: 会把role.roleName默认作为变量提交过去 所以想自 ...

  3. java基础 -- Collections.sort的两种用法

    /** * @author * @version * 类说明 */ package com.jabberchina.test; import java.util.ArrayList; import j ...

  4. Spring MVC - URL路径映射

    1. 普通映射 A. @RequestMapping("/test1") B. @RequestMapping(value={"/test1", "/ ...

  5. 根据生产场景对Linux系统进行分区

    转自:http://oldboy.blog.51cto.com/2561410/629558 老鸟谈生产场景如何对linux系统进行分区? █  前言:    我们买房子时,会考虑1室1厅,2室1厅, ...

  6. Git初步

    在多人参与开发的项目中,版本控制工具是必须的,网上有很多不错的教程,能简单使用就ok了,粘几篇教程,方便学习 首先我们要了解一些基本的概念,此处简单描述一下 (1)集中式版本控制系统: CVS.SVN ...

  7. Linux上Makefile管理java项目

    前面文章讲到了Linux上通过.spec文件与rpmbuild命令将java程序打包为RPM安装包, 现阶段遇到新的需求: 使用Makefile来操纵java的编译.打包 该需求以前面的内容为基础 可 ...

  8. Anytime项目开发记录2

    注册,登陆于密码找回.这是这次记录的主要内容. 首先,我们来看类图: 因为一直在改,所以与第二篇介绍项目框架时的图会有一些不一样. 代码都是非常简单的. 由于在注册和登陆这里,需要弹出一些对话框告诉用 ...

  9. 你可能会用到的"奇技赢巧"

    工作中偶尔会遇到一些不常见的问题,但是解决起来又极其麻烦,通常要找很多资料才能搞定,这里我总结了近段时间遇到的一些问题,可能会对你有帮助,高手勿喷. 1.关于iPhone最下面会弹出奇怪框框的问题 就 ...

  10. 阿牛的EOF牛肉串(递推)

    阿牛的EOF牛肉串 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...