QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71864#2582. 物理实验He_Ren100 ✓925ms6356kbC++983.4kb2023-01-12 02:07:522023-01-12 02:07:58

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:58]
  • 评测
  • 测评结果:100
  • 用时:925ms
  • 内存:6356kb
  • [2023-01-12 02:07:52]
  • 提交

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((ll)x*x + (ll)y*y);
	Vec ii = (Node){(ldb)x/len, (ldb)-y/len}, jj = (Node){(ldb)y/len, (ldb)x/len};
	
	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;
		
		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");
	}
	
	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

*/

詳細信息

Test #1:

score: 40
Accepted
time: 10ms
memory: 3232kb

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: 40
Accepted
time: 911ms
memory: 6264kb

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:

23150.53687320087192347273
1591692.18337961263023316860
21928.60438453371898503974
2894.66085455570646445267
14332.00000082250335253775
10772.20012003992815152742
61378.57524619891773909330
113952.27620851938263513148
34711.41135619064152706414
54764.07871613927272846922
76852.12247857465990819037
8...

result:

ok ok, 100 numbers

Test #3:

score: 20
Accepted
time: 925ms
memory: 6356kb

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:

13997587.65838192030787467957
17046702.41993344947695732117
46390075.52228959649801254272
7797517.42047588247805833817
24229463.20940786972641944885
13387746.94247283600270748138
11290240.30430250428617000580
55253758.74253495782613754272
60559802.17934723198413848877
80996320.54402686655521392822
1...

result:

ok ok, 100 numbers