描述

http://www.lydsy.com/JudgeOnline/problem.php?id=1615

分析

1.%.0lf是会四舍五入的!所以要强制转化成int.

 1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int maxn=1050+5;
5 const double eps=1e-10;
6 struct node{ double x,y,r; }a[maxn];
7 int n,s,t;
8 int q[maxn];
9 bool vis[maxn];
10 double xt,yt;
11 double s_[maxn],ans[maxn];
12 inline bool c(node a,node b){ return fabs((sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2))-a.r-b.r))<eps; }
13 int main(){
14     scanf("%d%lf%lf",&n,&xt,&yt);
15     for(int i=1;i<=n;i++){
16         scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
17         if(a[i].x==0.0&&a[i].y==0.0) s=i;
18         else if(a[i].x==xt&&a[i].y==yt) t=i;
19     }
20     int front=0,tail=0;
21     q[tail++]=s; vis[s]=true;  s_[s]=ans[s]=10000;
22     while(front!=tail){
23         int u=q[front++];
24         if(u==t){ printf("%d\n",(int)ans[u]); return 0; }
25         for(int v=1;v<=n;v++)if(!vis[v]&&c(a[u],a[v])){
26             s_[v]=-s_[u]*a[u].r/a[v].r;
27             ans[v]+=fabs(s_[v])+ans[u];
28             vis[v]=true;
29             q[tail++]=v;
30         }
31     }
32     return 0;
33 }
View Code

 1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int maxn=1050+5;
5 const double eps=1e-8;
6 struct node{ double x,y,r; }a[maxn];
7 int n,s,t;
8 int q[maxn];
9 double xt,yt;
10 bool vis[maxn];
11 inline bool c(node a,node b){ return fabs(sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2))-a.r-b.r)<eps; }
12 double dfs(int u,double sp,double ans){
13     if(u==t) return ans;
14     for(int v=1;v<=n;v++)if(!vis[v]&&c(a[u],a[v])){
15         vis[v]=true;
16         double S=-sp*a[u].r/a[v].r;
17         return dfs(v,S,ans+fabs(S));
18     }
19 }
20 int main(){
21     scanf("%d%lf%lf",&n,&xt,&yt);
22     for(int i=1;i<=n;i++){
23         scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
24         if(a[i].x==0.0&&a[i].y==0.0) s=i;
25         else if(a[i].x==xt&&a[i].y==yt) t=i;
26     }
27     vis[s]=true;
28     printf("%d\n",(int)dfs(s,10000,10000));
29     return 0;
30 }
View Code

posted @ 2016-06-13 17:44  晴歌。  阅读(167)  评论(0编辑  收藏  举报