洛谷P3434 [POI2006]KRA-The Disks

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\ 0001n,m300 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\ 0001ri​​1 000 000 000for 1\le i\le n1in) 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\ 0001kj​​1 000 000 000 for 1\le j\le m1jm) 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[300010],floor;
int main(){
    freopen("Cola.txt","r",stdin);
    scanf("%d%d",&n,&m);
    floor=n+1;
    for(int i=1;i<=n;i++)scanf("%d",&w[i]);
    int x;
    for(int i=1;i<=m;i++){
        scanf("%d",&x);
        bool flag=0;
        for(int j=1;j<floor;j++)
            if(w[j]<x){
                floor=j-1;
                flag=1;
                break;
            }
        if(!flag)floor=floor-1;
        if(floor<=0){
            printf("0");
            return 0;
        }
    }
    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=300005;
int a[N];
int main(){
    int n,m,now,x;
    scanf("%d%d",&n,&m);
    scanf("%d",&now);a[1]=now;
    int t;
    for(int i=2;i<=n;i++) scanf("%d",&t),now=a[i]=min(t,now);
    now=n+1;a[0]=1000000005;
    while(m--){
        scanf("%d",&x);
        //do{--now;}while(x>a[now]);
        int pos=upper_bound(a+1,a+now+1,x+1);
        if(!now){puts("0");return 0;}
    }
    printf("%d\n",now);
}
100分

 

转载于:https://www.cnblogs.com/thmyl/p/7505406.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值