Half, some thought doubling (lost my music: the sustainability of the stack)

On the half

From 8,17 exam simulation 24.

This question:

Monotone convex hull. (Find convex hull direction: Contact the college entrance mathematical linear programming)

Popping a backward operation is a bomb.
Sequence into a tree.
For the tree structure, parent-child relationships just recorded, can restore a whole tree.
Because to be persistent, then the stack here also becomes a tree.
Simply record on the stack father can be.
We do not even have to open an array as a stack.
Because of monotonicity, with multiplication, the effect is better.

Half, doubling some thoughts:

On two points, multiplying
1, the conventional array type stack due monotonic and continuous, may be two points and multiplying quick pop on sequence
    (here dichotomy means l, r, while loop, check (mid) bipartite)
    2, since you can only use half can also be used multiply, and that the difference between them where?
    It found: multiplication is learned while learning lca, is used to solve the tree problem. It can be said that he is monotone, but because of the special nature of the tree can not be half solved.
    Therefore, there has been doubling array. A good solution to the problem of binary tree ancestors.
    Corollary: multiplier array can also be used in a simpler sequence than the tree. He is the dichotomy of the enhanced version.
    Half of the problem can be resolved doubled mostly be resolved.
    Is used in many cases mid-half (binary multiplier can be split), because the mid direct, not fixed log, may be less.
    Multiplied i = 20 ~ 0 binary resolution, the complexity of the fixed log, with the upper half of the same, where the random a bit slower.
    No record some relationship, binary multiplication and split-half is the same.
    But it provides a lot of flexible and diverse array of functions doubled, making him more than a simple dichotomy adaptation, more functional.
    
    Annex: Ordinary binary multiplication wording :( compared little trouble ) ( handsome ah)
    int L, R & lt;
    for (int I, 20,0) {
        IF (Check (R- (I <<. 1))) R & lt = (R- (I <<. 1))
        the else L = (R- (I <<. 1)) -. 1
    }
  This problem Code:

#include <bits / STDC ++ H.>
 #define F. (I, A, B) for (int I = A RG; I <= B; I ++)
 #define IL inline 
 #define RG Register
 #define LL Long Long
 # DEFINE PF (a) the printf ( "% D", a)
 #define PHN the puts ( "")
 the using  namespace STD;
 int Read ();
 / * 
popped back operation is one of the shells. 
Sequence into a tree. 
For the tree structure, parent-child relationships just recorded, can restore a whole tree. 
Because to be persistent, then the stack here also becomes a tree. 
Simply record on the stack father can be. 
We do not even have to open an array as a stack. 
Because of monotonicity, with multiplication, the effect is better. 

Another: 1, the conventional array type stack due monotonic and continuous, may be two points and multiplying quick pop on sequence 
    (here dichotomy means l, r, while loop, check (mid) bipartite) 
    2, since either using the binary can be used multiply, and that the difference between them where? 
    found: multiplier It is learned while learning lca, is used to solve the tree problem. It can be said that he is monotone, but because of the special nature of the tree can not be half solved.
    Therefore, there has been doubling array. A good solution to the problem of binary tree ancestors. 
    Corollary: multiplier array can also be used in a simpler sequence than the tree. He is the dichotomy of the enhanced version. 
    Half of the problem can be resolved doubled mostly be resolved. 
    Is used in many cases mid-half (binary multiplier can be split), because the mid direct, not fixed log, may be less. 
    Multiplied i = 20 ~ 0 binary resolution, the complexity of the fixed log, with the upper half of the same, where the random a bit slower. 
    No record some relationship, binary multiplication and split-half is the same. 
    But it provides a lot of flexible and diverse array of functions doubled, making him more than a simple dichotomy adaptation, more functional. 
    
    Annex: Ordinary binary multiplication wording: 
    int L, R & lt; 
    for (int I, 20,0) { 
        IF (Check (R- (I <<. 1))) = R & lt (R- (I <<. 1)) 
        the else = L (R- (I <<. 1)) -. 1 
    } 
    
* / 
#define N 500 010
 int n-; 
IL Double min ( const  Double & X, const  Double & Y) { return X <Y?X: Y;}
 int F [N]; LL C [N]; 
Vector < int > Son [N]; // to record 1, convex hull multiplication ancestor. 
int Las [N << . 1 ] [ 20 is + 2 ]; LL DEP [N];
 int Jud ( int K, int J, int I) { return (C [I] -C [J]) * (DEP [J ] -dep [K]) <= (C [J] -C [K]) * (DEP [I] - DEP [J]);}
 void DFS ( int X) { 
    DEP [X] = DEP [F [ X]] + . 1 ;
     int P = F [X];
     for ( int I = 20 is ; I> = 0 ; - I) {
         IF (Las [P] [I] < 2 ) Continue ;
         int T = Las [P] [I];
         IF (Jud (Las [T] [ 0 ], T, X)) P = T; 
    } 
    IF ! (P = . 1 ) {
         IF (Jud (Las [P] [ 0 ], P, X)) P = Las [P] [ 0 ];
         / * 
            find the convex hull tangent: similar lca root lift. 
            Looking for a convex hull of the most forward point does not meet the conditions. 
            Then to judge his parent eligibility. 
            Skipped because if doubled, the slope would have been (i, j)> (j , k). 
            Finally, so to find a (i, j) <= ( j, k) point. 
            He then determine whether the parent.
            Laid convex pack for a sentence to be. 
        * / 
    }     
    Las [X] [0]=p;
    F(i,1,20)las[x][i]=las[las[x][i-1]][i-1];
    int ting=son[x].size()-1;
    F(i,0,ting){
        dfs(son[x][i]);
    }
}
int main(){
    n=read();
    F(i,1,n)c[i]=read();
    F(i,2,n)f[i]=read(),son[f[i]].push_back(i);
    dfs(1);
    F(i,2,n){
        printf("%.10lf\n",(double)(c[las[i][0]]-c[i])/(dep[i]-dep[las[i][0]]));
    }
}
il int read(){
    int s=0,f=0;char ch;
    while(ch=getchar(),f+=(ch=='-'),!isdigit(ch));
    for(;isdigit(ch);s=s*10+(ch^48),ch=getchar());
    return f?-s:s;
}
/*
g++ 3.cpp -g
./a.out
8
31516 11930 18726 12481 79550 63015 64275 7608
1 1 2 4 2 4 5

*/
View Code

 

Guess you like

Origin www.cnblogs.com/seamtn/p/11370324.html