我和#2测试点的输出一模一样,为什么判我WA?
查看原帖
我和#2测试点的输出一模一样,为什么判我WA?
936407
Oldxu114514楼主2025/7/20 10:17
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=50000;
int t;
int s,n,st,en;
int head[N],cnt,vis[N];
double dis[N];
double ans=12345678900.0;
int l;
double anss;
struct edge{
	int to,next;
	double val;
}e[6*N];
struct P{
	int id;
	double x;
	bool operator<(const P A)const
	{
		return x>A.x;
	} 
};
priority_queue<P> q;
struct node{
	int x1,y1;
	int x2,y2;
	int x3,y3;
	int x4,y4;
	double price;
}airport[505];
struct N{
	int x,y,id;
}plane[1005];
double gou(int x1,int x2,int y1,int y2)
{
	return sqrt(pow(x2-x1,2)+pow(y2-y1,2));
}
int f(int x,int y)
{
	//获取编号
	return (x-1)*4+y;
}
void add(int u,int v,double val)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	e[cnt].val=val;
	head[u]=cnt;
}
void init_array()
{
	l=0;
	for(int i=1;i<=50005;i++)
	{
		dis[i]=0x3f;
		vis[i]=0;
		head[i]=0;
	}
	for(int i=1;i<=300005;i++)
	{
		e[i].to=0;
		e[i].next=0;
		e[i].val=0;
	}
	for(int i=1;i<=1000;i++)
	{
		plane[i].x=0;
		plane[i].y=0;
		plane[i].id=0;
	}
	cnt=0;
	l=0;
}
void init_dis()
{
	for(int i=1;i<=50005;i++)
	{
		dis[i]=1145141919.0;
	}
}
void init()
{
	// 20250719 23:25改
	for(int i=1;i<=4*s;i++)
	{
		for(int j=1;j<=4*s;j++)
		{
			if(plane[i].id!=plane[j].id)
			{
				// 航线单独建边
				add(i,j,gou(plane[i].x,plane[j].x,plane[i].y,plane[j].y)*n);
			}
			else if(i==j)
			{
				continue;
			}
			else
			{
				// 高速公路单独建边
				add(i,j,gou(plane[i].x,plane[j].x,plane[i].y,plane[j].y)*airport[plane[i].id].price);
			}
		}
	}
}
void di(int start)
{
	q.push({start,0.0});
	dis[start]=0.0;
	while(!q.empty())
	{
		P gg=q.top();
		q.pop();
		int u=gg.id;
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i;i=e[i].next)
		{
			int v=e[i].to;
			if(dis[v]>dis[u]+e[i].val)
			{
				dis[v]=dis[u]+e[i].val;
				if(!vis[v])
				{
					q.push({v,dis[v]});
				}
			}
		}
	}
}
signed main()
{
	cin>>t;
	while(t--)
	{
		init_array();
		l=0;
		cin>>s>>n>>st>>en;
		for(int i=1;i<=s;i++)
		{
			cin>>airport[i].x1>>airport[i].y1>>airport[i].x2>>airport[i].y2>>airport[i].x3>>airport[i].y3>>airport[i].price;
			int nx=airport[i].x2-airport[i].x1;
			int ny=airport[i].y2-airport[i].y1;
			airport[i].x4=airport[i].x3+nx;
			airport[i].y4=airport[i].y3+ny;
			plane[++l].x=airport[i].x1;
			plane[l].y=airport[i].y1;
			plane[l].id=i;
			plane[++l].x=airport[i].x2;
			plane[l].y=airport[i].y2;
			plane[l].id=i;
			plane[++l].x=airport[i].x3;
			plane[l].y=airport[i].y3;
			plane[l].id=i;
			plane[++l].x=airport[i].x4;
			plane[l].y=airport[i].y4;
			plane[l].id=i;
		}
		init();
		for(int i=1;i<=4;i++)
		{
			init_dis();
			di(i);
			for(int j=4*(s-1)+1;j<=4*s;j++)
			{
				if(ans>dis[j])
				{
					ans=dis[j];
				}
			}
		}
		printf("%.1lf\n",ans);
	}
	return 0;
}

测试点#2: 1 3 10 1 3 2 2 2 1 1 2 10 2 12 12 2 22 12 1 22 22 22 32 32 22 10 输出: 214.1 程序输出: 214.1 情况

2025/7/20 10:17
加载中...