Poj 2991 crane

Source: Internet
Author: User

Poj_2991

If we rotate the beta angle of a line segment, all the lines above the line segment will rotate the beta angle, which is similar to the problem of adding a constant to the interval in the line segment tree, so you may wish to think about the line segment tree.

The next question is who the beta angle is relative to. In other words, each of our so-called line segments will rotate the beta angle, so who will rotate it around? In fact, if we only look at a line segment as a line segment, this rotation will be considered to be around a certain point, this point is the point of intersection between the line we rotate and the motionless line segment below it. If we want to continue this way, we will not be able to deal with it, because the fixed point around each rotation operation is not unique, we can't unify all the rotation operations, so we can't overlay the rotation operations, so we can't use the line segment tree.

However, if you change your mind, in fact, the beta angle is equal to the angle between the straight line after the line segment is rotated and the straight line before it is not rotated, the angle of a straight line can be expressed by the angle of a vector. If we regard a line segment as a vector, the angle of Beta is the angle of rotation of the vector. If you look at this, all the rotation operations can be unified together, and can also be superimposed, because this will not be limited to any point around, you just need to rotate the vector itself.OK. Speaking of this, we will find that the analysis in the previous section has gone astray from the very beginning. We have focused on "who is the angle of Beta ", because the relative things cannot be unified, and the results of different reference systems are different, we want to unify the rotation operations of each line segment, let's look at the absolute quantities changed by these rotation operations, and the vector is an absolute volume. It does not refer to other things, but only depends on the status of the line segment.

Let's take a look at how to implement it. As mentioned above, if we regard a line segment as a vector, each rotation operation can be regarded as adding a value (rotation angle of the vector) to all vertices in the interval ), there are two remaining problems: first, and most importantly, can we easily find the end point every time in this way? Second, the question shows the angle between the two line segments set each time. Can we easily convert them into the angle of rotation relative to the previous state?

For the first problem, since we have a vector of each line segment, we only need to sum these vectors and the final position is the end point, therefore, we only need to maintain the intervals and values of vectors. For the second problem, we can use an arrayDegree [I]IndicatesINumber of vectors and numberI-1The current angle of a vector, so that the current State is available. After each read operation, it is convenient to get the operation equivalent to the rotation angle, and then update it.Degree [I]You can. Each read operation affects only oneDegree []Will not affect otherDegree [].

All in all, we need to regard each line segment as a vector, maintain the range and sum of these vectors, and add a value to each element in the interval.

# Include <stdio. h>
# Include < String . H>
# Include <math. h>
# Define Maxd 10010
Const Double Pi = ACOs (- 1.0 );
Int N, m, a [maxd], a [maxd], degree [maxd], RD [ 4 * Maxd];
Struct Point
{
Double X, Y;
} DP [ 4 * Maxd];
Double Getrad ( Int X)
{
Return X * PI/ 180 ;
}
Void Build ( Int Cur, Int X, Int Y)
{
Int Mid = (x + y)> 1 , Ls = cur < 1 , RS = (cur <1 ) | 1 ;
Rd [cur] = 0 ;
DP [cur]. x = 0 , DP [cur]. Y = A [y]-A [X- 1 ];
If (X = y)
Return ;
Build (LS, X, mid );
Build (RS, Mid + 1 , Y );
}
Void Init ()
{
Int I;
A [ 0 ] = 0 ;
For (I = 1 ; I <= N; I ++)
{
Scanf ( " % D " , & A [I]);
A [I] = A [I- 1 ] + A [I];
Degree [I] = 0 ;
}
Build ( 1 , 1 , N );
}
Void Update ( Int Cur)
{
Int Ls = cur < 1 , RS = (cur < 1 ) | 1 ;
DP [cur]. X = DP [ls]. X + dp [RS]. x, DP [cur]. y = DP [ls]. Y + dp [RS]. y;
}
Void Rotate ( Double & Dx, Double & Dy, Double Rad)
{
Double X = DX, y = Dy;
DX = x * Cos (RAD)-y * sin (RAD );
DY = x * sin (RAD) + y * Cos (RAD );
}
Void Pushdown ( Int Cur)
{
Int Ls = cur < 1 , RS = (cur <1 ) | 1 ;
If (RD [cur])
{
Double Rad = getrad (RD [cur]);
Rd [ls] + = RD [cur], RD [RS] + = RD [cur];
Rotate (DP [ls]. X, DP [ls]. Y, rad );
Rotate (DP [RS]. X, DP [RS]. Y, rad );
Rd [cur] = 0 ;
}
}
Void Refresh ( Int Cur,Int X, Int Y, Int K, Int Delta)
{
Int Mid = (x + y)> 1 , Ls = cur < 1 , RS = (cur < 1 ) | 1 ;
If (X = y)
{
Double Rad = getrad (DELTA );
Rotate (DP [cur]. X, DP [cur]. Y, rad );
Return ;
}
Pushdown (cur );
If (Mid + 1 <K)
Refresh (RS, Mid + 1 , Y, K, Delta );
Else
{
Double Rad = getrad (DELTA );
If (K <= mid)
Refresh (LS, X, mid, K, Delta );
Rotate (DP [RS]. X, DP [RS]. Y, rad );
Rd [RS] + = delta;
}
Update (cur );
}
Void Solve ()
{
Int I, J, K, D, Delta;
For (I = 0 ; I <m; I ++)
{
Scanf ( " % D " , & K, & D );
++ K, D = d-180 ;
Delta = D-degree [k];
Degree [k] = D;
Refresh ( 1 , 1 , N, K, Delta );
Printf ( " %. 2f %. 2f \ n " , DP [ 1 ]. X, DP [ 1 ]. Y );
}
}
Int Main ()
{
Int T = 0 ;
While (Scanf ( " % D " , & N, & M) = 2 )
{
Init ();
If (T ++)
Printf ( " \ N " );
Solve ();
}
Return 0 ;
}

 

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.