Test instructions: N Kinds of food, each containing the probability of pepper is pi, now has chosen [l,r] this interval (subscript) of food, to choose another, so that the total food only one of the most likely to contain Pepper, asked which best, the same selection of the subscript small.
Solution: The solution is not written. Here are the official puzzle: http://acm.uestc.edu.cn/bbs/read.php?tid=5835
Maintain the maximum value of a prefix suffix.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#defineMod 1000000007#defineEPS 1e-8using namespacestd;#defineN 100002intPremax[n],bacmax[n],premin[n],bacmin[n];DoublePmax[n],pmin[n],bmax[n],bmin[n],p[n];intSgnDoublex) { if(x <-eps)return-1; if(X > EPS)return 1; return 0;}intMain () {intT,n,i,m,l,r; CIN>>T; while(t--) {scanf ("%d",&N); for(i=1; i<=n;i++) scanf ("%LF",&P[i]); premax[0] =0; premin[0] =0; pmax[0] = -1; pmin[0] =Mod; Bacmax[n+1] = n+1; bacmin[n+1] = n+1; Bmax[n+1] = -1; bmin[n+1] =Mod; for(i=1; i<=n;i++) {Premax[i]= premax[i-1]; Premin[i]= premin[i-1]; Pmax[i]= pmax[i-1]; Pmin[i]= pmin[i-1]; if(P[i] > Pmax[i]) pmax[i] = P[i], premax[i] =i; if(P[i] < pmin[i]) pmin[i] = P[i], premin[i] =i; } for(i=n;i>=1; i--) {Bacmax[i]= bacmax[i+1]; Bacmin[i]= bacmin[i+1]; Bmax[i]= bmax[i+1]; Bmin[i]= bmin[i+1]; if(P[i] >= bmax[i]) bmax[i] = P[i], bacmax[i] =i; if(P[i] <= bmin[i]) bmin[i] = P[i], bacmin[i] =i; } scanf ("%d",&m); while(m--) {scanf ("%d%d",&l,&s); L++,r++; DoubleB =1.0, E =0.0; for(i=l;i<=r;i++) B*= (1-p[i]), E + = p[i]/(1-P[i]); if(SGN (1-e) >0) { if(pmax[l-1] >= bmax[r+1]) printf ("%d\n", premax[l-1]-1); Elseprintf"%d\n", bacmax[r+1]-1); } Else { if(pmin[l-1] <= bmin[r+1]) printf ("%d\n", premin[l-1]-1); Elseprintf"%d\n", bacmin[r+1]-1); } } } return 0;}
View Code
UESTC 1015 Lweb and pepper--ago, suffix max