• Sound静音问题


    1342: [Baltic2007]Sound静音问题

    Time Limit: 5 Sec  Memory Limit: 162 MB
    Submit: 1183  Solved: 542
    [Submit][Status][Discuss]

    Description

    数字录音中,声音是用表示空气压力的数字序列描述的,序列中的每个值称为一个采样,每个采样之间间隔一定的
    时间。 很多声音处理任务都需要将录到的声音分成由静音隔开的几段非静音段。为了避免分成过多或者过少的非
    静音段,静音通常是这样定义的:m个采样的序列,该序列中采样的最大值和最小值之差不超过一个特定的阈值c。
     请你写一个程序,检测n个采样中的静音。

    Input

    第一行有三个整数n,m,c,分别表示总的采样数、静音的长度和静音中允许的最大噪音程度。
    第2行n个整数ai,表示声音的每个采样值,每两个整数之间用空格隔开。
    1<=n<=1000000,1<=m<=10000,0<=c<=10000
    0<=ai<=1,000,000

    Output

    列出了所有静音的起始位置i
    i满足max(a[i, . . . , i+m−1]) − min(a[i, . . . , i+m−1]) <= c
    每行表示一段静音的起始位置,按照出现的先后顺序输出。
    如果没有静音则输出NONE。

    Sample Input

    7 2 0
    0 1 1 2 3 2 2

    Sample Output

    2
    6

    HINT

     

    Source

    #include <bits/stdc++.h>
    
    #define rg register int
    using namespace std;
    typedef long long ll;
    const ll mod = 1e9 + 7;
    
    const int maxn = 2e6 + 10;
    
    int n, m, c;
    int o[maxn];
    int q1[maxn], q2[maxn], x_head, x_tail, n_head, n_tail;
    int res;
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("splay.txt", "r", stdin);
    #endif
        scanf("%d%d%d", &n, &m, &c);
        x_head = 1, x_tail = 0;
        bool check = false;
        for (register int i = 1; i <= n; ++i) {
            scanf("%d", &o[i]);
            while (x_head <= x_tail && i - q1[x_head] + 1 > m)++x_head;
            while (n_head <= n_tail && i - q2[n_head] + 1 > m)++n_head;
            while (n_head <= n_tail && o[q2[n_tail]] >= o[i])--n_tail;
            q2[++n_tail] = i;
            while (x_head <= x_tail && o[q1[x_tail]] <= o[i])--x_tail;
            q1[++x_tail] = i;
            if (i - m + 1 >= 1 && o[q1[x_head]] - o[q2[n_head]] <= c) {
                ++res;
                printf("%d
    ", i - m + 1);
                check = true;
            }
        }
        if (!check)puts("NONE");
        return 0;
    }
  • 相关阅读:
    Docker 私有仓库搭建
    事务提交与不同数据库的自增方式
    多环境切换&&注解方式&&增删改返回值问题
    查询缓存&&逆向工程
    Mybatis整合Log4j、延迟加载
    关联查询
    MyBatis实现动态SQL
    输出参数resultType
    MyBatis调用存储过程执行CRUD
    两种取值符号的异同
  • 原文地址:https://www.cnblogs.com/czy-power/p/11509704.html
Copyright © 2020-2023  润新知