Test instructions: give you a sequence that asks you to find a sub-sequence, which subtracts the average of the number of median digits from the subsequence.
Idea: The surface is directly said to be a single-peak function, I did not think much (at all), now seems to be a sort + three-point search.
Code: (Specially to learn the next three points.) ):
#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;intN;Long LongLEFTS,RIGHTS,LM,MR;intnum[200100],presum[200100];Doubleansx,anss,ans,hh=-1;DoubledfLong LongWLong Longl) { Long Longk=presum[w]-presum[w-l-1]+presum[n]-presum[n-L]; return(Double) k/(Double)(2*l+1)-(Double) num[w];}intMain () {//freopen ("win.in", "R", stdin); //freopen ("Win.out", "w", stdout);scanf"%d",&N); if(n<3) {printf ("0.00\n"); return 0; } for(intI=1; i<=n;i++) scanf ("%d",&Num[i]); presum[0]=1; Sort (num+1, num+n+1); for(intI=1; i<=n;i++) Presum[i]=presum[i-1]+Num[i]; for(intI=1; i<=n;i++) {lefts=0; Rights=min (n1, I-1); while(lefts<rights) {LM= (rights-lefts)/3+lefts; Mr=rights-(rights-lefts)/3; ANSX=DF (I,LM); anss=DF (I,MR); if(ANSX>ANSS) rights=mr-1; Elselefts=lm+1; } ans=DF (i,lefts); if(ans>hh) HH=ans; } printf ("%.2lf\n", HH); return 0;}
2017-9-3 in-school simulation T2 win number win