显示代码纯文本
#include<fstream>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;
ifstream fi("baler.in");
ofstream fo("baler.out");
const int MAXN=1100;
int N,father[MAXN];
class Gear
{
public:
double x,y,r,roll;
bool boo;
}g[MAXN];
bool Connect(int j,int k){return (g[j].x-g[k].x)*(g[j].x-g[k].x)+(g[j].y-g[k].y)*(g[j].y-g[k].y)==(g[j].r+g[k].r)*(g[j].r+g[k].r);}
int main()
{
int startG,endG;
double X_t,Y_t;
fi>>N>>X_t>>Y_t;
for(int i=1;i<=N;i++)
{
fi>>g[i].x>>g[i].y>>g[i].r;
g[i].boo=false;
if(g[i].x==0&&g[i].y==0)startG=i;
if(g[i].x==X_t&&g[i].y==Y_t)endG=i;
}
g[startG].roll=10000.0;
//=========================================================
memset(father,-1,sizeof(father));
deque <int> q;
q.push_back(startG);
g[startG].boo=true;
int tmp;
while(!g[endG].boo)
{
tmp=q.front();
q.pop_front();
for(int i=1;i<=N;i++)
if((!g[i].boo)&&Connect(tmp,i))
{
father[i]=tmp;
g[i].roll=g[tmp].roll*g[tmp].r/g[i].r;
g[i].boo=true;
q.push_back(i);
}
}
//==========================================================
double ans=g[startG].roll;
int j=endG;
while(father[j]!=-1)
{
ans+=g[j].roll;
j=father[j];
}
fo<<setiosflags(ios::fixed)<<setprecision(0)<<ans<<endl;
return 0;
}