首页 > 其他 > 详细

[Luogu] 洛谷 P3434 题解【[POI2006]KRA-The Disks】

时间:2018-10-14 20:34:11      阅读:145      评论:0      收藏:0      [点我收藏+]

因为一些物理原因,盘子一定是向下掉的

所以我们可以搞一个数组r_min[i]来维护r[1]~r[i]的最小值

然后再弄一个指针指向r_min[n]

每次读入一个k,通过向上移动指针来确定每一个盘子放的位置

蒟蒻的代码 QAQ

#include<bits/stdc++.h>
using namespace std;
int n,m;
int r[300001],k,r_min[300001];
bool flo[300001];
inline int read()
{
    int x=0,w=0;char ch=0;
    while(!(ch>=‘0‘&&ch<=‘9‘))
    {
        if(ch==‘-‘) w=1;
        ch=getchar();
    }
    while(ch>=‘0‘&&ch<=‘9‘)
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w?-x:x;
}
int main(){
    n=read();
    m=read();
    for(register int i=1;i<=n;++i)
    {
        r[i]=read();
        if(i!=1) r_min[i]=min(r_min[i-1],r[i]);
        else r_min[i]=r[i];
    }
    int kkk=n;
    for(register int i=1;i<=m;++i)
    {
        k=read();
        int toto=kkk;
        while(k>r_min[kkk]) kkk--;
        if(kkk<=0){cout<<0; return 0;}
        if(toto==kkk&&i!=1) kkk--;
    }
    cout<<kkk;
}

[Luogu] 洛谷 P3434 题解【[POI2006]KRA-The Disks】

原文:https://www.cnblogs.com/wo-shi-zhen-de-cai/p/9787493.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!