[Baltic2007]Sound静音问题(BZOJ1342)解题报告

 [Baltic2007]Sound静音问题(BZOJ1342)解题报告

【问题描述】

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

    n,m,c( 1<= n<=1000000,1<=m<=10000, 0<=c<=10000),分别表示总的采样数、静音的长度和静音中允许的最大噪音程度。

【分析】

    偶尔刷一下水题有益身心健康啊!!!就不多说了,可以用st算法,时间复杂度O(N log n),也可以用维护两个单调队列,一个递增,一个递减,直接看程序吧

【代码】

    

 1 var i,j,n,m,k,l,c,h1,h2,t1,t2:longint;
2 max,min:array[0..20000]of longint;
3 a:array[0..2000000]of longint;
4 bo:boolean;
5 begin
6 readln(n,m,c);
7 for i:=1 to n do read(a[i]);
8 h1:=1;t1:=1;h2:=1;t2:=1;
9 max[1]:=1;min[1]:=1;
10 bo:=false;
11 for i:=2 to n do
12 begin
13 while max[h1]+m<=i do inc(h1);
14 while (t1>=h1)and(a[max[t1]]<=a[i]) do dec(t1);
15 inc(t1);max[t1]:=i;
16 while min[h2]+m<=i do inc(h2);
17 while (t2>=h2)and(a[min[t2]]>=a[i]) do dec(t2);
18 inc(t2);min[t2]:=i;
19 if (a[max[h1]]-a[min[h2]]<=c)and(i>=m) then begin writeln(i-m+1);bo:=true;end;
20 end;
21 if not bo then writeln('NONE');
22 end.
posted @ 2011-11-09 07:59  N_C_Derek  阅读(463)  评论(1编辑  收藏  举报