QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71863#2582. 物理实验He_Ren40 5109ms6340kbC++983.5kb2023-01-12 02:07:412023-01-12 02:07:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 02:07:45]
  • 评测
  • 测评结果:40
  • 用时:5109ms
  • 内存:6340kb
  • [2023-01-12 02:07:41]
  • 提交

answer

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef double db;
#define x1 xxxxx1
#define x2 xxxxx2
#define y1 yyyyy1
#define y2 yyyyy2
const int MAXN = 1e4 + 5;
const ldb eps = 1e-8;

struct Node
{
	ldb x,y;
	inline void read(void){ int x_,y_; scanf("%d%d",&x_,&y_); x=x_; y=y_;}
};
typedef Node Vec;

inline Vec mul(Vec v, const Vec &i,const Vec &j){ return (Vec){i.x * v.x + j.x * v.y, i.y * v.x + j.y * v.y};}

struct Seg
{
	Node p,q;
	ldb k,b;
	bool type;
	inline void read(void){ p.read(); q.read();}
	
	inline void calc(void)
	{
		k = (q.y-p.y) / (q.x-p.x);
		b = p.y - k * p.x;
	}
}a[MAXN];

struct Data
{
	ldb x;
	int id;
}p[MAXN*2];
inline bool cmp(const Data &p,const Data &q){ return p.x < q.x;}

int now;

struct Cmp
{
	inline bool operator () (const int x,const int y) const
	{
		return a[x].k * p[now].x + a[x].b < a[y].k * p[now].x + a[y].b;
	}
};

bool has[MAXN*2][2];
ldb q[MAXN*2][2];

void solve(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		a[i].read();
	
	int sx,sy,x,y,l;
	scanf("%d%d%d%d%d",&sx,&sy,&x,&y,&l);
	
	x-=sx; y-=sy;
	for(int i=1; i<=n; ++i)
	{
		a[i].p.x -= sx; a[i].p.y -= sy;
		a[i].q.x -= sx; a[i].q.y -= sy;
	}
	
	ldb len = sqrt(x*x + y*y);
	Vec ii = (Node){(ldb)x/len, (ldb)-y/len}, jj = (Node){(ldb)y/len, (ldb)x/len};
	
	ldb dif = -114514;
	
	for(int i=1; i<=n; ++i)
	{
		a[i].p = mul(a[i].p, ii,jj);
		a[i].q = mul(a[i].q, ii,jj);
		if(a[i].q.x < a[i].p.x) swap(a[i].p, a[i].q);
		
		if(a[i].p.y < 0)
		{
			a[i].type = 1;
			a[i].p.y = -a[i].p.y;
			a[i].q.y = -a[i].q.y;
		}
		else a[i].type = 0;
		
		dif = max(dif, a[i].q.x - a[i].p.x);
		
		a[i].calc();
	}
	
	for(int i=1; i<=n; ++i)
		p[i*2-1] = (Data){a[i].p.x, i},
		p[i*2] = (Data){a[i].q.x, -i};
	sort(p+1, p+2*n+1, cmp);
	
	static set<int,Cmp> t[2];
	static ldb sum[MAXN*2];
	
	t[0].clear(); t[1].clear();
	
	for(int &i=now=1; i<2*n; ++i)
	{
		int id = p[i].id;
		
		if(id < 0) t[a[-id].type].erase(-id);
		else t[a[id].type].insert(id);
		
		sum[i] = 0;
		for(int k=0; k<=1; ++k)
			if(t[k].size())
			{	
				has[i][k] = 1;
				
				Seg &a = ::a[*t[k].begin()];
				ldb x = p[i+1].x - p[i].x;
				ldb y = a.k * x;
				sum[i] += sqrt(x*x + y*y);
				
				q[i][k] = a.k;
			}
			else has[i][k] = 0;
	}
	
	for(int i=2; i<2*n; ++i)
		sum[i] += sum[i-1];
	
	ldb ans = 0;
	for(int i=1,j=1; i<2*n; ++i)
	{
		while(j<2*n && p[j].x - p[i].x <= l + eps) ++j;
		
		ldb now = sum[j-1 - 1] - sum[i-1];
		for(int k=0; k<=1; ++k) if(has[j-1][k])
		{
			ldb x = min(l - (p[j-1].x - p[i].x), p[j].x - p[j-1].x);
			ldb y = q[j-1][k] * x;
			now += sqrt(x*x + y*y);
		}
		ans = max(ans, now);
		
//		printf("\n%Lf %Lf\n",p[i].x,p[j].x);
//		printf("%Lf\n",now);
//		
//		printf("\n");
	}
	
	for(int i=2*n-1, j=2*n-1; i>=1; --i)
	{
		while(j>=1 && p[i+1].x - p[j].x <= l + eps) --j;
		
		ldb now = sum[i] - sum[j];
		for(int k=0; k<=1; ++k) if(has[j][k])
		{
			ldb x = min(l - (p[i+1].x - p[j+1].x), p[j+1].x - p[j].x);
			ldb y = q[j][k] * x;
			now += sqrt(x*x + y*y);
		}
		ans = max(ans, now);
		
//		printf("%Lf %Lf\n",p[j].x,p[i+1].x);
//		printf("%Lf\n",now);
//		
//		printf("\n");
	}
	
	if(ans<0.0000005)
	{
		printf("%.20lf",(db)dif);
		exit(0);
	}
	printf("%.20lf\n",(db)ans);
}

int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

/*
1
1
1 1 5 1
2 0 3 0 2

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 40
Accepted
time: 9ms
memory: 3272kb

input:

100
100
7143 -4407 6148 -4332
-3698 1987 -3674 2827
-2240 -6374 -3784 -6054
149 599 327 597
-2580 -4497 -2820 -4347
9219 -1818 6904 502
-5893 1341 -4357 -1890
-3503 -3287 -1087 -1211
-1579 7118 -229 7556
6456 502 1926 -1748
540 6714 -528 6825
1561 8432 -701 8357
422 6998 -41 7462
-1793 3676 1602 517...

output:

939.77467737373183354066
454.29625812890094493923
270.09701286895983685099
17826.67862383721148944460
693.63384904838733291399
649.88518524601840908872
16035.00185850419802591205
1046.51944857072817285371
1243.73154267419181451260
620.68255375238834403717
1320.05662750815326944576
19054.040651341543...

result:

ok ok, 100 numbers

Test #2:

score: 0
Wrong Answer
time: 5109ms
memory: 6268kb

input:

100
10000
954303 48690 -14339 924721
464270 12166 -1609 433494
873644 42682 -12246 843861
449837 10414 -1919 418980
537496 14550 -6578 506603
552080 15962 -6594 521226
870138 42252 -12332 840332
57161 -702218 -671596 -43163
38907 -433607 -402515 -34409
445719 9913 -1981 414808
399734 5765 -1530 3686...

output:

-nan
4768013.26511685922741889954
-nan
2898.65041855663866954274
14332.00000082250335253775
-nan
173610.69923676742473617196
-nan
88002.14009334454021882266
54765.89434530265134526417
93249.15160902387287933379
-nan
5004.29656502697343967156
-nan
142220.06497674650745466352
-nan
-nan
17139.774912528...

result:

wrong output format Expected double, but "-nan" found

Test #3:

score: 0
Wrong Answer
time: 4297ms
memory: 6340kb

input:

100
10000
-636684471 -90006000 664665488 86376811
-263230447 -307903883 362658164 -223073366
-575841687 -121133860 614287459 40176834
-258935135 -268238570 347975250 -185982857
-287828480 -521064727 443096738 -422002609
-315452625 -391084040 435133968 -289354496
-560776752 -215271244 624810954 -5458...

output:

-nan
17058917.93095254898071289062
107003533.29578116536140441895
-nan
24233935.16749988868832588196
13387746.94247283600270748138
11363201.23073981888592243195
113849796.31867480278015136719
117690111.06491933763027191162
148904276.30530160665512084961
16696606.00029946677386760712
-nan
146867123.6...

result:

wrong output format Expected double, but "-nan" found