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_nr​1​​,r​2​​,⋯,r​n​​ (1\le r_i\le 1\ 000\ 000\ 0001≤r​i​​≤1 000 000 000for 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_mk​1​​,k​2​​,⋯,k​m​​ (1\le k_j\le 1\ 000\ 000\ 0001≤k​j​​≤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.

输入输出样例

输入样例#1:

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

2
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,w[],floor;
int main(){
freopen("Cola.txt","r",stdin);
scanf("%d%d",&n,&m);
floor=n+;
for(int i=;i<=n;i++)scanf("%d",&w[i]);
int x;
for(int i=;i<=m;i++){
scanf("%d",&x);
bool flag=;
for(int j=;j<floor;j++)
if(w[j]<x){
floor=j-;
flag=;
break;
}
if(!flag)floor=floor-;
if(floor<=){
printf("");
return ;
}
}
cout<<floor;
}

56分 暴力模拟

/*
考虑木块位置上移总次数<=n。
维护当前位置now
假设第i次木块宽x
所以每次如果前缀1..now存在点卡住x
也就是Min(a[1]..a[now])<x
就不断前移
时间O(n)
*/
#include<iostream>
#include<cstdio>
using namespace std;
const int N=;
int a[N];
int main(){
int n,m,now,x;
scanf("%d%d",&n,&m);
scanf("%d",&now);a[]=now;
int t;
for(int i=;i<=n;i++) scanf("%d",&t),now=a[i]=min(t,now);
now=n+;a[]=;
while(m--){
scanf("%d",&x);
//do{--now;}while(x>a[now]);
int pos=upper_bound(a+,a+now+,x+);
if(!now){puts("");return ;}
}
printf("%d\n",now);
}

100分

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

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

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

  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. 洛谷P3435 [POI2006]OKR-Period of Words [KMP]

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

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

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

  8. 洛谷 P3437 [POI2006]TET-Tetris 3D 解题报告

    P3437 [POI2006]TET-Tetris 3D 题目描述 The authors of the game "Tetris" have decided to make a ...

  9. 洛谷.3437.[POI2006]TET-Tetris 3D(二维线段树)

    题目链接 下落一个d*s的方块,则要在这个平面区域找一个最高的h' 更新整个平面区域的值为h+h' 对于本题,维护最大高度h和all 对于平面的x轴维护一棵线段树t1,每个t1的节点维护对应y轴的两棵 ...

随机推荐

  1. python之学习

    ------------------------------------------  基本语句解析 import:导入某些模块或者文件 import random: 导入生成随机数模块 import ...

  2. IOS 关于 NSUserDefault

    转载 并不是所有的东西都能往里放的.NSUserDefaults只支持: NSString, NSNumber, NSDate, NSArray, NSDictionary.   NSUserDefa ...

  3. ES6 Fetch API HTTP请求实用指南

    本次将介绍如何使用Fetch API(ES6 +)对REST API的 HTTP请求,还有一些示例提供给大家便于大家理解. 注意:所有示例均在带有箭头功能的 ES6中给出. 当前的Web /移动应用程 ...

  4. hdu-5818 Joint Stacks(模拟)

    题目链接: Joint Stacks Time Limit: 8000/4000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  5. 数据可视化入门之show me the numbers

           数据的可视化一直是自己瞎玩着学,近来想系统的学数据可视化的东西,于是搜索资料时看到有人推荐<show me the numbers>作为入门. 由于搜不到具体的书籍内容,只能 ...

  6. 注意!!一定要谨慎使用c/c++原生指针

    使用指针,要非常小心,今天在做一个小游戏时,就碰到一个使用原生指针的问题,找了好几个小时,才定位到问题的所在,晕. 主要是顶层逻辑中引用了一个指针,而在业务逻辑中将此指针删除了.这种在代码量很少的情况 ...

  7. MySQL活动期间订单满600元并且在活动日期之前超过30天没有下过单_20161030

    计算 活动期间订单满600元并且在活动日期之前超过30天没有下过单 首先拿到这个需求,首先需要明确活动日期区间 10.29-10.31,其次要取这个时间段内某天订单额最高的那天及订单额,再次需要判断这 ...

  8. Django 发送email配置详解及各种错误类型

    跟随Django Book的内容发送邮件不成功,总结一下需要配置好settings.py文件,还要注意一些细节. 1.在settings文件最后添加以下内容,缺一不可! EMAIL_HOST= 'sm ...

  9. ORA-00119: invalid specification for system parameter REMOTE_LISTENER

    环境说明:   RAC 启动数据库报 ORA-00119: invalid specification for system parameter REMOTE_LISTENER   . 检查 list ...

  10. poj 2069 Super Star——模拟退火(收敛)

    题目:http://poj.org/problem?id=2069 不是随机走,而是每次向最远的点逼近.而且也不是向该点逼近随意值,而是按那个比例:这样就总是接受,但答案还是要取min更新. 不知那个 ...