QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#121265#6124. King Of ZombiesEastKingWA 1ms3724kbC++172.5kb2023-07-07 20:13:092023-07-07 20:13:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-07 20:13:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3724kb
  • [2023-07-07 20:13:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int M=1005,inf=1e9;
const double eps=1e-8;
#define fi first
#define se second
int n,D;
int dcmp(double x){
	if(fabs(x)<eps)return 0;
	return x>0?1:-1;
}
struct node{
	double x,y;
	node operator +(const node&tmp)const{
		return (node){x+tmp.x,y+tmp.y};
	}
	node operator -(const node&tmp)const{
		return (node){x-tmp.x,y-tmp.y}; 
	}
	node operator /(const double &a)const{
		return (node){x/a,y/a}; 
	}
	node operator *(const double &a)const{
		return (node){x*a,y*a}; 
	}
}A[M],V[M];
double dis[M];
typedef pair<double,int> Pi;
double cross(node a,node b){
	return a.x*b.y-a.y*b.x;
}
double length(node a){
	return sqrt(a.x*a.x+a.y*a.y);
}
double disl(node p,node a,node b){
	node v=p-a;
	node u=b-a;
	return fabs(cross(v,u))/length(u);
}
double dot(node a,node b){
	return a.x*b.x+a.y*b.y;
}
double calc(node a,node b){
	if(dot(a,b)<=0)return 0;
	return length(a)/length(b);
}
node Intersect_line(node a,node b,node c,node d){//两直线交点 
//if(cross(b-a,d-c)==0)return node(inf,inf);//前提 不共线
	double s1=cross(d-c,a-c);
	double s2=cross(d-c,b-c);
	return a+(b-a)*s1/(s1-s2);
}
vector<int>update(int x){
	vector<int>Q;
	for(int i=1;i<=n;i++){
		if(i==x)continue;
		node v=V[x]-V[i];
		node p=A[i];
		node a=A[x];
		node b=a+v;
		if(length(v)==0){
			if(length(a-p)<=D){
				if(dis[i]>dis[x]){
					dis[i]=dis[x];
					Q.push_back(i);
				}
			}
			continue;
		}
		double d=disl(p,a,b);
		if(d>D)continue;
		double del=sqrt(D*D-d*d);
		node dir=v/length(v)*del;
		node nl={-v.y,v.x};
		node pot=Intersect_line(p,p+nl,a,b);
		//printf("x=%d i=%d\n",x,i);
		double tl=calc(pot+dir-a,v),tr=calc(pot-dir-a,v);
		if(tl>tr)swap(tl,tr);
		//printf("%lf %lf\n",tl,tr);
		if(dis[x]<=tr){
			double val=max(dis[x],tl);
			//printf("%lf\n",val);
			if(dis[i]>val){
				dis[i]=val;
				Q.push_back(i);
			}
		}
	}
	return Q;
}
void solve(){
	priority_queue<Pi,vector<Pi>,greater<Pi>>Q;
	Q.push({0,0});
	while(!Q.empty()){
		auto now=Q.top();
		Q.pop();
		int x=now.se;
		if(now.fi>dis[x])continue;
		vector<int>val=update(x);
		for(auto v:val){
			Q.push({dis[v],v});
		}
	}
}
int main(){
	scanf("%d %d",&n,&D);
	for(int i=1;i<=n;i++)dis[i]=inf;
	for(int i=0;i<=n;i++){
		int x,y,a,b;
		scanf("%d %d",&x,&y);
		scanf("%d %d",&a,&b);
		A[i]={x,y};
		V[i]={a,b};
	}
	solve();
	for(int i=1;i<=n;i++){
		if(dis[i]==inf){
			printf("-1\n");
		}else {
			printf("%.10f\n",dis[i]);
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3724kb

input:

5 3
0 0 3 0
10 10 0 -3
1 1 -1 -1
16 1 -1 0
100 100 100 100
-100 -3 10 0

output:

0.0000000000
0.0000000000
3.0000000000
0.0000000000
14.2857142857

result:

wrong answer 1st numbers differ - expected: '2.6262266', found: '0.0000000', error = '1.0000000'