题解:这个嘛,其实就是通过各个齿轮的位置和齿轮的半径建立一个联系,然后从驱动轮一直搜索到工作轮(在这里BFS,DFS均可),由于题目中声明了不会存在两个不同的齿轮带动同一个齿轮的情况,所以麻烦少了很多,且路径唯一。还有值得注意的是,最好在计算各个轮过程中要用实型变量来存储,防止由于整除而导致的精度误差。。。
1 type
2 point=^node;
3 node=record
4 g:longint;
5 w:extended;
6 next:point;
7 end;
8
9 var
10 i,j,k,l,m,n,f,r,q,x1,y1:longint;
11 a:array[0..2000,1..3] of longint;
12 b:array[0..2000] of point;
13 c:array[0..2000] of extended;
14 d,e:array[0..2000] of longint;
15 p:point;
16 ans:extended;
17 function cut(x,y:longint):boolean;
18 begin
19 exit((sqr(a[x,1]-a[y,1])+sqr(a[x,2]-a[y,2]))=sqr(a[x,3]+a[y,3]))
20 end;
21 procedure add(x,y:longint);
22 var
23 p:point;
24 begin
25 new(p);
26 p^.g:=y;
27 p^.w:=a[y,3]/a[x,3];
28 p^.next:=b[x];
29 b[x]:=p;
30 end;
31 begin
32 readln(n,x1,y1);
33 for i:=1 to n do
34 readln(a[i,1],a[i,2],a[i,3]);
35 for i:=1 to n do
36 for j:=1 to i-1 do
37 begin
38 if cut(i,j) then
39 begin
40 add(i,j);
41 add(j,i);
42 end;
43 end;
44 for i:=1 to n do
45 if (a[i,1]=0) and (a[i,2]=0) then
46 begin
47 l:=i;
48 break;
49 end;
50 for i:=1 to n do
51 if (a[i,1]=x1) and (a[i,2]=y1) then
52 begin
53 q:=i;
54 break;
55 end;
56 c[l]:=1;
57 fillchar(e,sizeof(e),0);
58 d[1]:=l;e[l]:=-1;
59 f:=1;r:=2;
60 while f<r do
61 begin
62 p:=b[d[f]];
63 while p<>nil do
64 begin
65 if e[p^.g]=0 then
66 begin
67 d[r]:=p^.g;
68 e[p^.g]:=d[f];
69 c[p^.g]:=c[d[f]]*p^.w;
70 inc(r);
71 end;
72 p:=p^.next;
73 end;
74 inc(f);
75 end;
76 ans:=0;
77 while q<>-1 do
78 begin
79 ans:=ans+(10000/c[q]);
80 q:=e[q];
81 end;
82 writeln(trunc(ans));
83 end.
84