标签:join ace bing blog 题目 color cte check nbsp
Description
Input
Output
Sample Input
2 1
10 5
1 90
3 2
5 5 5
1 270
2 90
Sample Output
5.00 10.00
-10.00 5.00
-5.00 10.00
Source
题解:
我是没想到是线段树,看了是线段树后自己yy了一个建线段树的方法,好像跟书上的不一样。
书上的方法:
我的代码:
1 program rrr(input,output); 2 const 3 eps=1e-10; 4 type 5 treetype=record 6 l,r:longint; 7 x,y,d:double; 8 end; 9 var 10 a:array[0..40040]of treetype; 11 c:array[0..10010]of double; 12 b:array[0..10010]of longint; 13 n,m,i,x:longint; 14 y,t,xx,yy:double; 15 procedure build(k,l,r:longint); 16 var 17 mid,i:longint; 18 begin 19 a[k].l:=l;a[k].r:=r;a[k].x:=0;a[k].d:=0; 20 if l=r then begin a[k].y:=b[l];exit; end; 21 mid:=(l+r)>>1;i:=k+k; 22 build(i,l,mid);build(i+1,mid+1,r); 23 a[k].y:=a[i].y+a[i+1].y; 24 end; 25 procedure pushdown(k:longint); 26 var 27 i:longint; 28 begin 29 if a[k].l=a[k].r then a[k].d:=0; 30 if abs(a[k].d)<eps then exit; 31 i:=k+k; 32 xx:=a[i].x*cos(a[k].d)-a[i].y*sin(a[k].d); 33 yy:=a[i].x*sin(a[k].d)+a[i].y*cos(a[k].d); 34 a[i].x:=xx;a[i].y:=yy;a[i].d:=a[i].d+a[k].d; 35 inc(i); 36 xx:=a[i].x*cos(a[k].d)-a[i].y*sin(a[k].d); 37 yy:=a[i].x*sin(a[k].d)+a[i].y*cos(a[k].d); 38 a[i].x:=xx;a[i].y:=yy;a[i].d:=a[i].d+a[k].d; 39 a[k].d:=0; 40 end; 41 procedure change(k:longint); 42 var 43 mid,i:longint; 44 begin 45 pushdown(k); 46 if x<a[k].l then 47 begin 48 xx:=a[k].x*cos(t)-a[k].y*sin(t); 49 yy:=a[k].x*sin(t)+a[k].y*cos(t); 50 a[k].x:=xx;a[k].y:=yy; 51 a[k].d:=t; 52 exit; 53 end; 54 mid:=(a[k].l+a[k].r)>>1;i:=k+k; 55 if x<mid then change(i); 56 change(i+1); 57 a[k].x:=a[i].x+a[i+1].x;a[k].y:=a[i].y+a[i+1].y; 58 end; 59 begin 60 assign(input,‘r.in‘);assign(output,‘r.out‘);reset(input);rewrite(output); 61 while not eof do 62 begin 63 readln(n,m);if (n=0) and (m=0) then break; 64 for i:=1 to n do begin read(b[i]);c[i]:=pi; end; 65 build(1,1,n); 66 for i:=1 to m do 67 begin 68 readln(x,y);t:=y/180*pi-c[x];c[x]:=y/180*pi; 69 change(1); 70 writeln(a[1].x:0:2,‘ ‘,a[1].y:0:2); 71 end; 72 writeln; 73 end; 74 close(input);close(output); 75 end.
标签:join ace bing blog 题目 color cte check nbsp
原文地址:http://www.cnblogs.com/Currier/p/6680798.html