QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#115242#5904. Twirling Towards Freedomlyx123886a12388649 ✓2635ms3840kbC++142.7kb2023-06-25 11:57:232023-06-25 11:57:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-25 11:57:24]
  • 评测
  • 测评结果:49
  • 用时:2635ms
  • 内存:3840kb
  • [2023-06-25 11:57:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long//与基准判时,值域最大3e16,不会爆long long
using namespace std;
int read() {
	char ch=getchar();int res=0,fl=1;
	while(ch<'0'||ch>'9'){if(ch=='-') fl=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
	return res*fl;
}
const int N=5005;
struct vec{
	int x,y;
}a[N][4],p[4];
vec operator +(vec A,vec B){return (vec){A.x+B.x,A.y+B.y};}
vec operator *(vec A,int k){return (vec){A.x*k,A.y*k};}
vec operator *(int k,vec A){return (vec){A.x*k,A.y*k};}
int operator *(vec A,vec B){return A.x*B.x+A.y*B.y;}
double dis(vec A){return sqrt(1.0*A.x*A.x+1.0*A.y*A.y);}//自乘可能爆long long!!要用double
int n,m,test_case=0;
double calc(vec lim) {
	for(int k=0;k<4;++k) {
		p[k]=a[1][k];//可能不如0,一定要注意!!
		for(int i=2;i<=n;++i) p[k]=((p[k]*lim)<(a[i][k]*lim))?a[i][k]:p[k];
	}
/*	vec ans=(vec){0,0},res=(vec){0,0};
	for(int i=1;i<=m;++i) {
		res=res+p[(i-1)%4];
		if((res*lim)>(ans*lim)) ans=res;
	}//!!!我这块求max写错了!!
	return dis(ans);*/
	vec v[4],ans,base=p[0]+p[1]+p[2]+p[3];
	v[0]=(vec){0,0};
	ans=v[0];
	v[1]=p[0];
	v[2]=p[0]+p[1];
	v[3]=p[0]+p[1]+p[2];
	if(m<4) {
		for(int i=0;i<=m;++i) if((v[i]*lim)>(ans*lim)) ans=v[i];
		return dis(ans);//
	}
	else {
		for(int i=0;i<4;++i) {
			vec tmp=v[i];
			if((base*lim)>0) tmp=tmp+(base*((m-i)/4));
			if((tmp*lim)>(ans*lim)) ans=tmp;
		}
		return dis(ans);
	}
	/*	vec base=p[0]+p[1]+p[2]+p[3],ans=(vec){0,0};
	ans=ans+(((base*lim)>0)?(base*max((m/4)-1,0ll)):(vec){0,0});
	m=m-4*max((m/4)-1,0ll);//把>=8的部分都减4
	vec v[8],maxn;
	v[0]=(vec){0,0};
	maxn=v[0];
	for(int i=1;i<=7;++i) {
		v[i]=v[i-1]+p[(i-1)%4];
		if(m>=i&&(v[i]*(lim))>(maxn*lim)) maxn=v[i];
	} 
//	if(m>=1&&(v0*lim)>(maxn*lim)) maxn=v0;
//	if(m>=2&&(v1*lim)>(maxn*lim)) maxn=v1;
//	if(m>=3&&(v2*lim)>(maxn*lim)) maxn=v2;
//	printf("(%d,%d)(%d,%d)\n",maxn.x,maxn.y,ans.x,ans.y);
	return dis(ans+maxn);*/
}
void solve() {
	test_case++;
	double Ans=0.0;
	n=read();m=read();
	for(int i=1;i<=n;++i) {
		int x=read(),y=read();
		a[i][0]=(vec){(x-y),(x+y)};
		a[i][1]=(vec){(x+y),-(x-y)};
		a[i][2]=(vec){-(x-y),-(x+y)};
		a[i][3]=(vec){-(x+y),x-y};
	}
//	for(int i=1;i<=n;++i) printf("(%lld,%lld)(%lld,%lld)(%lld,%lld)(%lld,%lld)\n",a[i][0].x,a[i][0].y,a[i][1].x,a[i][1].y,a[i][2].x,a[i][2].y,a[i][3].x,a[i][3].y);
	for(int i=1;i<=10000;++i) {
		int x=(1ll*rand()*rand()-1ll*rand()*rand())%100000,y=(1ll*rand()*rand()-1ll*rand()*rand())%100000;
		Ans=max(Ans,calc((vec){x,y}));
	}
	printf("Case #%lld: %.10lf\n",test_case,Ans);
	return ;
}
signed main()
{
	//freopen("freedom.in","r",stdin);
	//freopen("freedom.out","w",stdout);
	int T=read();
	while(T--) {
		solve();
	}
	return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 116ms
memory: 3708kb

input:

100
4
1
-2 4
1 -2
4 1
0 2
1
4
-5 0
2
5
-1 1
-2 2
10
8
-842 -60
148 -967
327 -600
-546 -346
-196 -267
-833 -156
334 -791
974 -382
-499 -785
519 -657
10
7
444 786
-313 649
-377 954
-872 316
505 714
678 170
40 -971
-290 -649
-824 -797
357 -653
10
9
-384 -28
267 -243
507 -628
-189 -656
373 -879
-115 -81...

output:

Case #1: 6.3245553203
Case #2: 10.0000000000
Case #3: 6.3245553203
Case #4: 8072.6630054772
Case #5: 9582.0846374889
Case #6: 9520.9500576361
Case #7: 3136.8787034248
Case #8: 9405.6161945935
Case #9: 9809.6108995209
Case #10: 8356.3092331483
Case #11: 8863.7475144546
Case #12: 10066.9729313235
Case...

result:

ok correct! (100 test cases)

Subtask #2:

score: 39
Accepted

Test #2:

score: 39
Accepted
time: 2635ms
memory: 3840kb

input:

100
200
59153573
81 -81
-252 252
864 -864
-691 691
-599 599
-520 520
-835 835
334 -334
259 -259
-469 469
374 -374
-36 36
932 -932
-518 518
-882 882
-150 150
-392 392
29 -29
8 -8
-259 259
192 -192
-863 863
-88 88
-219 219
-118 118
485 -485
-953 953
-980 980
-14 14
433 -433
-672 672
352 -352
196 -196
...

output:

Case #1: 82359120550.7561340332
Case #2: 84510626188.2999267578
Case #3: 70661053401.3009338379
Case #4: 109064878459.4080963135
Case #5: 31887461051.9420623779
Case #6: 44597031797.9429397583
Case #7: 16108038453.3387355804
Case #8: 88820696855.7596588135
Case #9: 38768573735.9652099609
Case #10: 2...

result:

ok correct! (100 test cases)

Extra Test:

score: 0
Extra Test Passed