Medium POJ 2991 Crane, geometric + line tree.

Source: Internet
Author: User

Description

ACM has bought a new crane (Crane-Je?áb). The crane consists of n segments of various lengths, connected by flexible joints. The end of the i-th segment is joined to the beginning of the i + 1-th one, for 1≤i < N. The beginning of the first segment is a fixed at point with coordinates (0, 0) and it end at point with coordinates (0, W), where w is the length of the first segment. All of the segments lie always in one plane, and the joints allow arbitrary rotation in that plane. After series of unpleasant accidents, it is decided that software that controls the crane must contain a piece of code th At constantly checks the position of the end of Crane, and stops the crane if a collision should happen.

Your task is to write a part of this software that determines the position of the end of the n-th segment after each comma nd. The state of the crane was determined by the angles between consecutive segments. Initially, all of the angles is straight, i.e., 180o.    The operator issues commands, the angle in exactly one joint. Test instructions is an excavator, hungry ...  The crane, the robotic arm, has n knots, which can be rotated, asking the last position after each rotation. At the beginning of the thought is to use an array to represent each point, and then use a segment tree to update an interval, but timed out, because each update to let the last update all update thoroughly, in fact, is directly all updated, but rather than direct simulation. Later looked at the puzzle, referring to the vector ...  is to use the array to record all the vectors in the interval and then all the interval is the answer, and, every time the D degree is rotated D degrees, no difference ... Another two hours of this problem, or the first two hours of this year ... Achievements of the time did not update thoroughly, it seems that the future of their own testing must be more than a set of data .... The code is as follows:
#include <iostream>#include<cstdio>#include<cmath>#defineLson l,m,po*2#defineRson m+1,r,po*2+1using namespacestd;structstate{Doublex, y;};Const DoublePi=atan2 (1.0,1.0)*4; State bit[10004*4];intcol[10004*4];intrang[10004];voidChangeintPointCT) {    DoubleTang; DoubleLen; Tang=atan2 (bit[po].y,bit[po].x); Len=SQRT (bit[po].x*bit[po].x+bit[po].y*bit[po].y); Tang+=ct*pi/180.0; bit[po].x=len*cos (tang); Bit[po].y=len*sin (tang);}voidPushup (intPO) {bit[po].x=bit[po*2].x+bit[po*2+1].x; Bit[po].y=bit[po*2].y+bit[po*2+1].y;}voidPushdown (intPO) {    if(Col[po]) {Change (PO*2, Col[po]); Change (PO*2+1, Col[po]); Col[po*2]+=Col[po]; Col[po*2+1]+=Col[po]; COL[PO]=0; }}voidBuild_tree (intLintRintPO) {Col[po]=0;//DON ' T forget!!!    if(l==R) {inttemp; bit[po].x=0; COL[PO]=0; scanf ("%d",&temp); Bit[po].y=temp; return; }    intM= (L+R)/2;    Build_tree (Lson);    Build_tree (Rson); Pushup (PO);}voidUpdateintUlinturintUtintLintRintPO) {    if(ul<=l&&ur>=R) {change (po,ut); COL[PO]+=ut; COL[PO]%= the; return;    } pushdown (PO); intM= (L+R)/2; if(ul<=M) Update (Ul,ur,ut,lson); if(ur>M) Update (Ul,ur,ut,rson); Pushup (PO);}intMain () {intN,c; intb; intcas=0;  while(~SCANF ("%d%d",&n,&c)) {if(cas++) printf ("\ n"); Build_tree (1N1);  for(intI=1; i<=n;++i) rang[i]=0;  for(intI=1; i<=c;++i) {scanf ("%d%d",&a,&b); b-= the; if(b==- the) b= the; Update (a+1, N,b-rang[a],1N1); Rang[a]=b; printf ("%.2LF%.2lf\n", bit[1].x,bit[1].y); }    }    return 0;}
View Code

Medium POJ 2991 Crane, geometric + line tree.

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.