求助,有几个点差一点对了
查看原帖
求助,有几个点差一点对了
261262
WaltVBAlston楼主2021/12/1 18:41

RT,这个点:

11 345 87
159 212 80
0 -120 95
23 314 30
345 87 53
96 -48 25
0 0 25
261 -48 106
63 84 80
138 -48 17
-25 350 30
71 278 30

output:

44412

我的output:44413

不知道为什么,感觉没问题啊

code:

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
struct node{
	int ind;
	double spin;
	double now;
};
int n;
double xt,yt;
vector <int> e[1105];
double x[1105],y[1105],r[1105];
queue <node> q;
bool vis[1105]={false};
double dis(int i,int j){
	return sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
}
int main(){
	cin>>n>>xt>>yt;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i]>>r[i];
		if(x[i]==0&&y[i]==0)
			q.push((node){i,10000,10000});
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			if(i==j)
				continue;
			if(dis(i,j)==r[i]+r[j])
				e[i].push_back(j),e[j].push_back(i);
		}
	while(!q.empty()){
		node t=q.front();
		q.pop();
		if(x[t.ind]==xt&&y[t.ind]==yt){
			cout<<fixed<<setprecision(0)<<t.now;
			break;
		}
		for(auto i:e[t.ind]){
			int to=i;
			double to_spin=t.spin*r[t.ind]/r[to];
			if(vis[to])
				continue;
			vis[to]=true;
			q.push((node){to,to_spin,t.now+to_spin});
		}
	}
	return 0;
}
2021/12/1 18:41
加载中...