洞窟里有一道长长的通道.它由N(1≤N≤25000)段道尾相连构成,编号分别为1到N.每个通道有一个阈值,其范围在[1,10^9]依次通过i..j的通道,那奶牛的体重指数就不能超过i..j通道中阈值的最小值.贝茜有Q(1≤Q≤25000)个问题,想请教你由i到j的通道的阈值的最小值.
标签:
题解:RMQ模板题。。。感觉自己水水哒
1 /************************************************************** 2 Problem: 3381 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:272 ms 7 Memory:2220 kb 8 ****************************************************************/ 9 10 var 11 i,j,k,l,m,n,h:longint; 12 a:array[0..30000,0..16] of longint; 13 function min(x,y:longint):longint; 14 begin 15 if x<y then min:=x else min:=y; 16 end; 17 begin 18 readln(n,m); 19 h:=trunc(ln(n)/ln(2)+1); 20 for i:=1 to n do readln(a[i,0]); 21 for i:=1 to h do 22 for j:=1 to n-trunc(exp(ln(2)*i))+1 do 23 a[j,i]:=min(a[j,i-1],a[j+trunc(exp(ln(2)*(i-1))),i-1]); 24 25 for i:=1 to m do 26 begin 27 readln(j,k); 28 l:=trunc(ln(k-j+1)/ln(2)); 29 writeln(min(a[j,l],a[k-trunc(exp(ln(2)*l))+1,l])); 30 end; 31 readln; 32 end.
3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4415942.html