枚举WA28pts悬棺求条
查看原帖
枚举WA28pts悬棺求条
1300775
RC4010楼主2025/7/18 18:42
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=2001;
struct node{
	char op;
	int fx;
};
struct point{
	int x,y;
};
long double far(point p,point q){
	long double xx=p.x,yy=q.y;
	long double j1=p.y-yy,j2=q.x-xx;
	return sqrt(j1*j1*1.0+j2*j2*1.0);
}
queue<node>q1,q2;
signed main(){
	int x,y,m,a,b,n;
	cin>>x>>y>>m;
	for(int i=1;i<=m;i++){
		int d;
		char c;
		int f=1;
		cin>>d>>c;
		if (d<0) f=-1;
		for(int j=1;j<=abs(d);j++){
			q1.push({c,f});
		}
	} 
	cin>>a>>b>>n;
	for(int i=1;i<=n;i++){
		int d;
		char c;
		int f=1;
		cin>>d>>c;
		if (d<0) f=-1;
		for(int j=1;j<=abs(d);j++){
			q2.push({c,f});
		}
	}
	point p,q;
	p.x=x,p.y=y;
	q.x=a,q.y=b;
	long double ans=far(p,q);
	while(q1.size()||q2.size()){
		if (q1.size()){
			node dw=q1.front();
			q1.pop();
			if (dw.op=='X'){
			    p.x+=dw.fx;
		    }
		    else{
			    p.y+=dw.fx; 
		    }
		}
		if (q2.size()){
			node dv=q2.front();
			q2.pop();
		    if (dv.op=='X'){
			    q.x+=dv.fx;
		    }
		    else{
			    q.y+=dv.fx; 
		    }
		}
		ans=min(ans,far(p,q));
	}
	printf("%.2Lf",ans);
}
2025/7/18 18:42
加载中...