Test instructions: give you n something, and then each thing inside a matter each add AI, and then let you to each thing in the same amount of B material, ask here face |sum (a)-sum (b) | The largest interval of this value is the smallest, ask you how much B matter should be added?
The puzzle: Suppose B substance plus x, so that s (i,j) =sigma (a[k]-x) is required to minimize max|s (I,J) | (I,j all belong to 1 to N)
Light so see the basic is no idea, I was too stupid, here Leng for a long time do not know how to do, in fact, should be simplified
Max|s (I,J) | = MAX (max (S (i,j),-S (i,j))) = Max (max (S (i,j), Max (-S (i,j)) = Max (A, B)
A=max (S (i,j)), B=max (-S (i,j))
Because to minimize Ans=max (A, B), to observe the value of X on the effect of ans, x increases, A becomes smaller, B becomes larger, and a, a, is a monotone function, and then takes two monotone functions of Max, just the minimum value of ans at the intersection of a, B function, that is, the image is a first descent after the rise So can be solved with three points (a bit ingenious ah, it seems I still need to work, or be QWB god Ben on the ground friction
Ps. The old urchin giant and taught me the important conclusion is that the absolute value is a convex function, can use three points, max (convex function, convex function) or convex function, can also use three points Otz, important conclusion, to grasp OH
#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <cstring># Include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment ( linker, "/stack:102400000,102400000") using namespace std; #define MAX 200005#define MAXN 500005#defin E maxnode 105#define sigma_size 2#define lson l,m,rt<<1#define Rson m+1,r,rt<& Lt;1|1#define LRT rt<<1#define RRT rt<<1|1#define Middle int m= (r+l) >>1 #define LL Long long#define ull unsigned long long#define mem (x,v) memset (x,v,sizeof (x)) #d Efine lowbit (x) (x&-x) #define PII pair<int,int> #define BITS (a) __builtin_popcount (a) #d Efine Mk Make_pair#define Limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL inff = 0x3f3f;const double pi = ACOs ( -1.0); const double inf = 1e18;const double eps = 1e-9;const LL mod = 1e9+7;const ull mx = 1e9+7;/******** /inline void RI (int &x) {char C; while (C=getchar ()) < ' 0 ' | | c> ' 9 '); x=c-' 0 '; while ((C=getchar ()) >= ' 0 ' && c<= ' 9 ') x= (x<<3) + (x<<1) +c-' 0 ';} /*****************************************************/int A[max];d ouble dp[max],dp1[max];int n;double get (Double X ) {dp[0]=dp1[0]=0; Double ret=0; for (int i=1;i<=n;i++) {Dp[i]=max (dp[i-1]+ (A[i]-x), (a[i]-x)); Dp1[i]=max (dp1[i-1]+ (X-a[i]), (X-a[i])); Ret=max (Ret,dp[i]); Ret=max (Ret,dp1[i]); } return ret;} int main () {//freopen ("test.txt", "R", stdin); int t; cin>>t; while (t--) {cin>>n; int mini=inf,maxn=0; for (int i=1;i<=n;i++) {scanf ("%d", &a[i]); Mini=min (Mini,a[i]); Maxn=max (Maxn,a[i]); } double L=MINI,R=MAXN; for (int i=0;i<100;i++) {double ll= (2*l+r)/3; Double rr= (2*r+l)/3; if (get (LL) <get (RR)) R=RR; else L=ll; } printf ("%.6f\n", L); } return 0;}
CSU 1728 linear stepwise copolymerization reaction (three points)