QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135702#2582. 物理实验2024zll100 ✓1281ms4844kbC++143.3kb2023-08-05 22:48:182023-08-05 22:48:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 22:48:19]
  • 评测
  • 测评结果:100
  • 用时:1281ms
  • 内存:4844kb
  • [2023-08-05 22:48:18]
  • 提交

answer

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<set>
#include<vector>
typedef long long ll;
typedef double real;
const int maxn=10000;
const real eps=1e-14;
int sign(const real num){
	return num<-eps?-1:num>eps;
}
struct Vector{
	real x,y;
	Vector(){}
	Vector(const real x,const real y):x(x),y(y){}
	void input(){
		scanf("%lf%lf",&x,&y);
	}
	friend Vector operator-(const Vector&A,const Vector&B){
		return Vector(A.x-B.x,A.y-B.y);
	}
	friend real Dot(const Vector&A,const Vector&B){
		return A.x*B.x+A.y*B.y;
	}
	friend real Cross(const Vector&A,const Vector&B){
		return A.x*B.y-A.y*B.x;
	}
	real Length(){
		return hypot(x,y);
	}
	real Length2(){
		return x*x+y*y;
	}
	Vector rotate(const real _cos_,const real _sin_){
		return Vector(x*_cos_-y*_sin_,y*_cos_+x*_sin_);
	}
};
struct Segment{
	Vector A,B;
	real k,b;
}S[maxn];
Vector L1,L2;
int n;
real L,L_len,L_len2,_cos_,_sin_,s,t,cur_val,cur_sum,ans;
struct Query{
	int type,id;
	real pos;
	Query(const int type,const int id,const real pos):type(type),id(id),pos(pos){};
	friend bool operator<(const Query&A,const Query&B){
		return sign(A.pos-B.pos)?A.pos<B.pos:(A.type&1)>(B.type&1);
	}
};
std::vector<Query>Q;
struct cmp_s{
	bool operator()(const int u,const int v){
		return S[u].k*s+S[u].b<S[v].k*s+S[v].b;
	}
};
std::set<int,cmp_s>set_s_u,set_s_d;
struct cmp_t{
	bool operator()(const int u,const int v){
		return S[u].k*t+S[u].b<S[v].k*t+S[v].b;
	}
};
std::set<int,cmp_t>set_t_u,set_t_d;
void solve(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)S[i].A.input(),S[i].B.input();
	L1.input(),L2.input();
	scanf("%lf",&L);
	for(int i=0;i<n;i++)S[i].A=S[i].A-L1,S[i].B=S[i].B-L1;
	L2=L2-L1,L1=Vector(0,0);
	L_len2=L2.Length2(),L_len=sqrt(L_len2),L/=L_len,_cos_=L2.x/L_len2,_sin_=-L2.y/L_len2;
	for(int i=0;i<n;i++)S[i].A=S[i].A.rotate(_cos_,_sin_),S[i].B=S[i].B.rotate(_cos_,_sin_);
	L1=L1.rotate(_cos_,_sin_),L2=L2.rotate(_cos_,_sin_);
	Q.clear();
	for(int i=0;i<n;i++){
		if(S[i].A.x>S[i].B.x)std::swap(S[i].A,S[i].B);
		S[i].k=(S[i].B.y-S[i].A.y)/(S[i].B.x-S[i].A.x);
		S[i].b=S[i].A.y-S[i].k*S[i].A.x;
		Q.emplace_back(0,i,S[i].A.x);
		Q.emplace_back(1,i,S[i].B.x);
		Q.emplace_back(2,i,S[i].A.x+L);
		Q.emplace_back(3,i,S[i].B.x+L);
	}
	std::sort(Q.begin(),Q.end());
	t=-1e10,s=t-L,cur_val=0,cur_sum=0,ans=0;
	for(size_t i=0,j;i<Q.size();i=j){
		cur_sum+=(Q[i].pos-t)*cur_val;
		for(j=i;j<Q.size()&&Q[j].pos<Q[i].pos+eps;j++){
			const int type=Q[j].type,id=Q[j].id;
			if((type&1)==0)t=Q[i].pos,s=t-L;
			if(type==0){
				if(S[id].A.y>0)set_t_u.emplace(id);
				else set_t_d.emplace(id);
			}else if(type==1){
				if(S[id].A.y>0)set_t_u.erase(id);
				else set_t_d.erase(id);
			}else if(type==2){
				if(S[id].A.y>0)set_s_u.emplace(id);
				else set_s_d.emplace(id);
			}else if(type==3){
				if(S[id].A.y>0)set_s_u.erase(id);
				else set_s_d.erase(id);
			}
		}
		t=Q[i].pos,s=t-L;
		cur_val=0;
		cur_val+=(set_t_u.empty()?0:hypot(S[*set_t_u.begin()].k,1))+(set_t_d.empty()?0:hypot(S[*set_t_d.rbegin()].k,1));
		cur_val-=(set_s_u.empty()?0:hypot(S[*set_s_u.begin()].k,1))+(set_s_d.empty()?0:hypot(S[*set_s_d.rbegin()].k,1));
		ans=std::max(ans,cur_sum);
	}
	printf("%.10lf\n",ans*L_len);
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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.7746773737
454.2962581289
270.0970128690
17826.6786238372
693.6338490484
649.8851852460
16035.0018585042
1046.5194485707
1243.7315426742
620.6825537524
1320.0566275082
19054.0406513415
1062.0222738142
684.4295601859
421.1793537617
1051.7111712395
850.6338037141
22608.7457029564
13436.1931537422
...

result:

ok ok, 100 numbers

Test #2:

score: 40
Accepted
time: 1145ms
memory: 4844kb

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.5368732011
1591692.1833796075
21928.6043845340
2894.6608545557
14332.0000008225
10772.2001200388
61378.5752461963
113952.2762085177
34711.4113561910
54764.0787161391
76852.1224785771
87090.6178374857
5004.1045959034
79872.5168546977
69493.4970644517
90559.4047765717
86547.5955539095
17134.6650...

result:

ok ok, 100 numbers

Test #3:

score: 20
Accepted
time: 1281ms
memory: 4844kb

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.6583819557
17046702.4199333824
46390075.5222897604
7797517.4204758890
24229463.2094075382
13387746.9424728137
11290240.3043024037
55253758.7425345853
60559802.1793482155
80996320.5440259129
16696606.0002883188
18751679.4997102842
76860841.8119300157
22030848.0532681607
68197919.1737810522
2...

result:

ok ok, 100 numbers