烦请大佬们帮忙看看错哪里了(会关注的)
查看原帖
烦请大佬们帮忙看看错哪里了(会关注的)
1162093
jimmy0926楼主2024/4/2 17:28

蒟蒻代码:(码风过丑,请别介意)

#include <bits/stdc++.h>
using namespace std;
int n,x,y;
map <array <int,2>,int> r;
vector <array <int,2> > vis;
int f(int,int,int,int);
int js(int,int,int);
void bfs(void);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)
	{
		int tx,ty,tr;
		cin>>tx>>ty>>tr;
		r.insert({{tx,ty},tr});
	}
	if(x==0 && y==0)
	{
		cout<<10000;
		return 0;
	}
	bfs();
	return 0;
}
int f(int a,int b,int c,int d)
{
	return int(sqrt(int(pow(abs(c-a),2))+int(pow(abs(d-b),2))));
}
int js(int a,int b,int c)
{
	return a*b/c;
}
void bfs(void)
{
	queue <array <int,4> > que;
	que.push({0,0,10000,10000});
	vis.push_back({0,0});
	do
	{
		auto a=que.front();
		que.pop();
		for(map<array<int,2>,int>::iterator it=r.begin();
			it!=r.end();it++)
		{
			if(f((it->first)[0],(it->first)[1],a[0],a[1])!=(it->second)+r[{a[0],a[1]}]
			   || find(vis.begin(),vis.end(),it->first)!=vis.end())
				continue;
			vis.push_back(it->first);
			int tmp=js(a[2],r[{a[0],a[1]}],it->second);
			que.push({(it->first)[0],(it->first)[1],tmp,tmp+a[3]});
			if((it->first)[0]==x && (it->first)[1]==y)
			{
				cout<<tmp+a[3];
				return;
			}
		}
	}while(!que.empty());
}

麻烦了,谢谢

2024/4/2 17:28
加载中...