CF578C weakness and poorness three points

Source: Internet
Author: User

In fact, three points is a single-peak function of the most value of things, usage is more uniform. The problem is that the observation found that the value is a single-peak function, then the enumeration of T three points on the line.

The problem is dry:

Given an array of length n, the AI, a real number x, so that the sequence a1-x,a2-x,..., an-x is the least good degree. The degree of uncertainty is defined as the maximum value of the bad degree of all successive sub-sequences of a sequence. The bad degree is defined as the absolute value of the sum of all the positions of a sequence. Enter the first row N. The second row n number, which represents AI. Outputs a real number that is accurate to 6 decimal places, indicating the minimum degree of uncertainty. 

Code:

#include <iostream>#include<cstdio>#include<cmath>#include<ctime>#include<queue>#include<algorithm>#include<cstring>using namespacestd;#defineDuke (I,a,n) for (int i = a;i <= n;i++)#defineLV (i,a,n) for (int i = a;i >= n;i--)#defineClean (a) memset (A,0,sizeof (a))Const intINF =1<< -; typedefLong LongLl;typedefDoubledb;template<classT>voidRead (T &x) {    CharC; BOOLOP =0;  while(c = GetChar (), C <'0'|| C >'9')        if(c = ='-') op =1; X= C-'0';  while(c = GetChar (), C >='0'&& C <='9') x= x *Ten+ C-'0'; if(OP) x =-x;} Template<classT>voidwrite (T x) {if(X <0) Putchar ('-'), x =-x; if(x >=Ten) Write (X/Ten); Putchar ('0'+ x%Ten);}Const intMAXN = 2e5 +5;ConstDB EPS = 1e-8;intARR[MAXN];d b arr1[maxn];intn;db Calc (db arr[]) {db T=0; DB Res= arr[0]; Duke (I,0N1) {T= Arr[i] +T; Res=Max (res,t); if(T <EPS) T=0; }    returnRes;} DB Solve (db t) {Duke (I,0N1) {Arr1[i]= Arr[i]-T; } DB x1=Calc (arr1); Duke (I,0N1) Arr1[i]= -Arr1[i]; DB X2=Calc (arr1); DB x=Max (Fabs (x1), fabs (x2)); returnx;}intMain () {read (n); intMaxnum =-10001, Minnum =10001; Duke (I,0N1) {read (arr[i]); Maxnum=Max (maxnum,arr[i]); Minnum=min (minnum,arr[i]); }    intdcnt = -; DB L= Minnum, R =Maxnum;  while(dcnt--) {db M1= L + (r-l)/3; db M2= R-(r-l)/3; DB X1=solve (M1); DB X2=solve (m2); if(X1 >x2) {L=M1; }        Else{R=m2; }} DB Res=solve (L); printf ("%.8lf\n", RES); return 0;}

CF578C weakness and poorness three points

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.