zoukankan      html  css  js  c++  java
  • 洛谷 P2251 质量检测

    题目背景

    题目描述

    为了检测生产流水线上总共N件产品的质量,我们首先给每一件产品打一个分数A表示其品质,然后统计前M件产品中质量最差的产品的分值Q[m] = min{A1, A2, ... Am},以及第2至第M + 1件的Q[m + 1], Q[m + 2] ... 最后统计第N - M + 1至第N件的Q[n]。根据Q再做进一步评估。

    请你尽快求出Q序列。

    输入输出格式

    输入格式:

     

    输入共两行。

    第一行共两个数N、M,由空格隔开。含义如前述。

    第二行共N个数,表示N件产品的质量。

     

    输出格式:

     

    输出共N - M + 1行。

    第1至N - M + 1行每行一个数,第i行的数Q[i + M - 1]。含义如前述。

     

    输入输出样例

    输入样例#1: 复制
    10 4
    16 5 6 9 5 13 14 20 8 12
    
    输出样例#1: 复制
    5
    5
    5
    5
    5
    8
    8
    

    说明

    [数据范围]

    30%的数据,N <= 1000

    100%的数据,N <= 100000

    100%的数据,M <= N, A <= 1 000 000

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int n,m;
    int st[1000010][21];
    int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int query(int l,int r){
        int k=log2(r-l+1);
        return min(st[l][k],st[r-(1<<k)+1][k]);
    }
    int main(){
        n=read();m=read();
        for(int i=1;i<=n;i++)    st[i][0]=read();
        for(int j=1;j<=21;j++)
            for(int i=1;i+(1<<j)-1<=n;i++)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
        for(int i=1;i<=n-m+1;i++){
            int l=i,r=i+m-1;
            printf("%d
    ",query(l,r));
        }
    }
    100
  • 相关阅读:
    Enables DNS lookups on client IP addresses 域名的分层结构
    移除 URL 中的 index.php
    Design and Architectural Goals
    The Model represents your data structures.
    If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
    UNION WHERE
    cookie less
    http 2
    UNION DISTINCT
    联合约束 CONCAT()
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/9925626.html
Copyright © 2011-2022 走看看