2017-9-3 in-school simulation T2 win number win

Source: Internet
Author: User

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&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.