显示代码纯文本
#include <cstdio>
using namespace std;
int way[1050]={0},map[1050][1049],que[1102500],dad[1102500];
double x[1050],y[1050],r[1050],spe[1102500];
bool used[1050]={false};
int main(void)
{
freopen("baler.in","r",stdin);
freopen("baler.out","w",stdout);
int i,j,n,st,en,tail=0,head=0,temp;
double xt,yt,total=0;
scanf("%d %lf %lf\n",&n,&xt,&yt);
for (i=0;i<n;i++)
{
scanf("%lf %lf %lf\n",&x[i],&y[i],&r[i]);
if (x[i]==0&&y[i]==0)
st=i;
if (x[i]==xt&&y[i]==yt)
en=i;
for (j=0;j<i;j++)
if ((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])==(r[i]+r[j])*(r[i]+r[j]))
{
map[i][way[i]++]=j;
map[j][way[j]++]=i;
}
}
que[0]=st;
spe[0]=10000;
dad[0]=-1;
used[st]=true;
while (tail<=head)
{
for (i=0;i<way[que[tail]];i++)
if (!used[map[que[tail]][i]])
{
head++;
que[head]=map[que[tail]][i];
spe[head]=spe[tail]*r[que[tail]]/r[que[head]];
dad[head]=tail;
used[que[head]]=true;
if (que[head]==en)
{
temp=head;
while (temp!=-1)
{
total+=spe[temp];
temp=dad[temp];
}
printf("%.0lf\n",total);
fclose(stdin);
fclose(stdout);
return(0);
}
}
tail++;
}
fclose(stdin);
fclose(stdout);
return(0);
}