1615: [Usaco2008 mar]the loathesome hay baler Trouble's hay baler

Source: Internet
Author: User

1615: [Usaco2008 mar]the loathesome hay baler troublesome hay baler time limit:5 Sec Memory limit:64 MB
submit:574 solved:226
[Submit] [Status] Description

Farmer John's newly bought hay baler the most chaotic in the world, it does not have a clear internal transmission like a normal machine, but rather, n (2 <= n <= 1050) Gears interact, each of which may drive multiple gears. FJ recorded its 3 parameters for each gear I: The x_i,y_i represents the position coordinates of the gear center ( -5000 <= x_i <=; -5000 <= y_i <=); R_i indicates the radius of the gear (3 <= R_i <= 800). The position of the drive gear is 0, 0, and FJ also knows that the final working gear is located in the x_t,y_t. The drive gear rotates clockwise with a rotational speed of 10,000 revolutions per hour. Your task is to determine the speed of all gears in the transmission sequence. A transmission sequence is defined as the set of all gears used in the process of transmitting energy from a drive gear to a working gear. The transmission of meaningless gears to energy should be ignored. In a radius of Rd, the speed of S-turn/hourly gear driven, and it meets the radius of the RX gear speed will be-s*rd/rx rpm. The minus sign in front of s means that the steering of another gear driven by a gear will be reversed with its turn. The FJ is only interested in the absolute value of all gear speeds in the entire transmission sequence, and your task is converted to this value accordingly. All gears in the machine except the drive gears are driven by a different gear and do not appear to drive the same gear with 2 separate gears. Believe you can easily write a program to complete these calculations:)

Input

* Line 1th: 3 integers separated by a space: n,x_t,y_t

* 2nd. N+1 Line: Section i+1 describes the position and radius of the gear I: x_i,y_i, and R_i

Output

* Line 1th: Outputs the absolute value of all gear speeds that play a part in the drive, including drive gears and working gears. Only the integer part of the answer needs to be output

Sample Input4 32 54
0 0 10
0 30 20
32 54 20
-40 30 20


The machine has a total of 4 gears, located in the 0,0 is a radius of 10 drive gear, which led to the
0,30 a gear with a radius of 20. This gear is also indirectly driven by a 32, 54, radius of 20
Working gears, as well as a redundant gear at -40,30, with a radius of equally 20.

Sample Output20000

HINT

Output Description:


Gear Position radius Speed

1 (0,0) 10 10,000

2 (0,30) 20-5,000

3 (32,54) 20 5,000

------

The sum of the absolute value of gear speed: 20,000

Source

Silver

The problem: this, is actually through the position of the gears and the radius of the gear to establish a connection, and then from the drive wheel has been searching to the working wheel (here Bfs,dfs can), because the title stated that there will not be two different gears to drive the same gear situation, so the trouble is much less, and the path is unique. It is also worth noting that it is best to use real variables to store in the calculation of each wheel to prevent precision errors caused by the division of integers ...

1 type2Point=^node;3Node=Record4 G:longint;5 w:extended;6 Next:point;7     End;8 9 varTen I,j,k,l,m,n,f,r,q,x1,y1:longint; OneA:Array[0.. -,1..3] ofLongint; AB:Array[0.. -] ofPoint ; -C:Array[0.. -] ofextended; -D,e:Array[0.. -] ofLongint; the P:point; - ans:extended; - functionCut (X,y:longint): boolean; -          begin +Exit (Sqr (A[x,1]-a[y,1]) +sqr (a[x,2]-a[y,2])) =sqr (A[x,3]+a[y,3])) -          End; + procedureAdd (x,y:longint); A           var at P:point; -           begin - new (p); -p^.g:=y; -P^.w:=a[y,3]/a[x,3]; -p^.next:=B[x]; inb[x]:=p; -           End; to begin + readln (n,x1,y1); -       fori:=1  toN Do theREADLN (A[i,1],a[i,2],a[i,3]); *       fori:=1  toN Do $           forj:=1  toI-1  DoPanax Notoginseng              begin -                   ifCut (I,J) Then the                      begin + Add (i,j); A Add (j,i); the                      End; +              End; -       fori:=1  toN Do $          if(A[i,1]=0) and(A[i,2]=0) Then $             begin -l:=i; - Break ; the             End; -       fori:=1  toN DoWuyi          if(A[i,1]=X1) and(A[i,2]=Y1) Then the             begin -q:=i; Wu Break ; -             End; Aboutc[l]:=1; $Fillchar (E,sizeof (E),0); -d[1]:=l;e[l]:=-1; -f:=1; r:=2; -       whileF<r Do A            begin +p:=B[d[f]]; the                  whileP<>Nil  Do -                       begin $                            ife[p^.g]=0  Then the                               begin thed[r]:=p^.g; thee[p^.g]:=D[f]; thec[p^.g]:=c[d[f]]*P^.W; - Inc (R); in                               End; thep:=P^.next; the                       End; About Inc (f); the            End; theans:=0; the       whileq<>-1  Do +            begin -Ans:=ans+ (10000/c[q]); theq:=E[q];Bayi            End; the Writeln (trunc (ans)); the End. -                     

1615: [Usaco2008 mar]the loathesome hay baler Trouble's hay baler

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.