社区讨论

震惊,样例过不了A了3个点???

P1027[NOIP 2001 提高组] Car 的旅行路线参与者 9已保存回复 11

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
11 条
当前快照
1 份
快照标识符
@mi6olf5f
此快照首次捕获于
2025/11/20 08:16
4 个月前
此快照最后确认于
2025/11/20 08:28
4 个月前
查看原帖
CPP
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define Fast register 
#define numm(i,j) (i-1)*4+j
const int maxx=402;
const int maxn=1002;
const double inf=0x3f3f3f3fll;
int s,t,A,B;
double e[maxn][maxn],tt,ans=inf;
int w,top=0;
inline char getc(){
    static char buf[1<<14],*p1=buf,*p2=buf;
    return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
    int data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getc();
    if(ch=='-') w=-1,ch=getc();
    while(ch>='0'&&ch<='9') data=data*10+ch-'0',ch=getc();
    return data*w;
}
struct point{
	int x,y,num;
	point(){x=0,y=0,num=0;} 
	inline void In(Fast int u,Fast int j)
	{
		x=read(),y=read();
		num=numm(u,j);
		return;
	}
	inline void Out()
	{
		printf("%d %d",x,y);
		putchar('\n');
		return;
	}
	point operator-(const point s) const
	{
		point ans;
		ans.x=x-s.x;
		ans.y=y-s.y;
		return ans;
	}
	inline int dot(point s)
	{
		return x*s.x+y*s.y;
	}
	inline point hhd(point s,point t)
	{
		point res;
		res.x=t.x+s.x-x;
		res.y=t.y+s.y-y;
		return res;
	}
	double dis(point s)
	{
		double a=x-s.x,b=y-s.y; 
		return sqrt(a*a+b*b);
	}
}a,b,c,d,que[maxn*maxn];
inline void memsett()
{
	for(Fast int i=1;i<=maxx;i++)
		for(Fast int j=1;j<=maxx;j++)
			e[i][j]=inf;
	return;
}
inline point lwd(Fast int u,Fast int j)
{
	point s1,s2,s3,ans;
	s1=b-a,s2=c-a,s3=c-b;
	if(s1.dot(s2)==0) ans=a.hhd(b,c);
	else if(s1.dot(s3)==0) ans=b.hhd(a,c);
	else ans=c.hhd(a,b);
	ans.num=numm(u,j);
	return ans;
}
inline void debug()
{
	for(Fast int i=1;i<=20;i++)
	{
		for(Fast int j=1;j<=20;j++)
		(e[i][j]==inf)?printf("00000 "):printf("%0.3lf ",e[i][j]);
		putchar('\n');
	}
	return;
}
inline void add(point a,point b,int ww)
{
	int x=a.num,y=b.num;
	if(e[x][y]<inf) return;
	e[x][y]=ww*(a.dis(b));
	return;
}
int main()
{
    int m;
    m=read();
    while(m--)
	{
		memsett();
		top=0,ans=inf;
		
		s=read(),t=read(),A=read(),B=read();
		for(Fast int i=1;i<=s;i++)
		{
			a.In(i,1),b.In(i,2),c.In(i,3),w=read();
			d=lwd(i,4);		
		//	d.Out();	
			que[++top]=a;
			que[++top]=b;
			que[++top]=c;
			que[++top]=d;
			add(a,b,w);
			add(a,c,w);
			add(a,d,w);
			add(b,c,w);
			add(b,d,w);
			add(c,d,w);
		}
	//	debug();
	//for(Fast int i=1;i<=top;i++)
	//printf("que[%d]:",i),que[i].Out();
	for(Fast int i=1;i<=top;i++)
		for(Fast int j=i+1;j<=top;j++)
			if(((i+3)/4)!=((j+3)/4)) add(que[i],que[j],t);
		
		for(Fast int k=1;k<=(s<<2);k++)
			for(Fast int i=1;i<=(s<<2);i++)
				for(Fast int j=1;j<=(s<<2);j++)
					e[i][j]=min(e[i][j],e[i][k]+e[k][j]);

	//	debug();
		int sti=numm(A,1),stj=numm(A,1)+3,eni=numm(B,1),enj=numm(B,1)+3;
		for(Fast int i=sti;i<=stj;i++)
			for(Fast int j=eni;j<=enj;j++)
				ans=min(e[i][j],ans);
	//	debug();
		printf("%.1lf",ans);
	} 
	return 0;
 } 

回复

11 条回复,欢迎继续交流。

正在加载回复...