QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#38384#1182. LighthouseswyhaoAC ✓4294ms4280kbC++1.9kb2022-07-05 13:09:462022-07-05 13:09:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-05 13:09:48]
  • 评测
  • 测评结果:AC
  • 用时:4294ms
  • 内存:4280kb
  • [2022-07-05 13:09:46]
  • 提交

answer

#include<cstdio>
#include<cmath>
using namespace std;
typedef double db;
const int N=305;
int T,n,m,cnt;
struct node{
	int x,y,next;
}edge[N*N];
int h[N];
void add(int i,int x,int y){
	edge[i].x=x;edge[i].y=y;
	edge[i].next=h[x];h[x]=i;
}
db px[N],py[N],dp[N][N][2];
bool vis[N][N][2];
db max1(db a,db b){
	return a>b?a:b;
}
db w(int i,int j){
	return sqrt((px[i]-px[j])*(px[i]-px[j])+(py[i]-py[j])*(py[i]-py[j]));
}
db f(int i,int j,int v){
	i=i%n;j=j%n;
	if(i==0) i=n;
	if(j==0) j=n;
//	printf("%d %d\n",i,j);
	if(i==j) return 0;
	if(vis[i][j][v]) return dp[i][j][v];
	vis[i][j][v]=true;
	if(i<j){
		for(int k=h[i],y;k;k=edge[k].next){
			y=edge[k].y;
			if(v==0){
				if(i<y and y<=j){
					dp[i][j][v]=max1(dp[i][j][v],w(i,y)+max1(f(y,j,v),f(y,i+1,v^1)));
				}
			}else{
				if(y<i or j<=y){
					dp[i][j][v]=max1(dp[i][j][v],w(i,y)+max1(f(y,j,v),f(y,i-1,v^1)));
				}
			}
		}
	}else{
		for(int k=h[i],y;k;k=edge[k].next){
			y=edge[k].y;
			if(v==1){
				if(j<=y and y<i){
					dp[i][j][v]=max1(dp[i][j][v],w(i,y)+max1(f(y,j,v),f(y,i-1,v^1)));
				}
			}else{
				if(y<=j or i<y){
					dp[i][j][v]=max1(dp[i][j][v],w(i,y)+max1(f(y,j,v),f(y,i+1,v^1)));
				}
			}
		}
	}
	return dp[i][j][v];
} 
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dp[i][j][0]=dp[i][j][1]=0;
				vis[i][j][0]=vis[i][j][1]=false;
			}
			h[i]=0;
		}
		for(int i=1;i<=n;i++){
			scanf("%lf%lf",&px[i],&py[i]);
		}
		scanf("%d",&m);
		cnt=0;
		for(int i=1,x,y;i<=m;i++){
			scanf("%d%d",&x,&y);
			add(++cnt,x,y);
			add(++cnt,y,x);
		}
//		for(int i=1;i<=cnt;i++) printf("%d--%d\n",edge[i].x,edge[i].y);
//		puts(""); 
		db ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				ans=max1(ans,max1(f(i,j,0),f(i,j,1)));
//				printf("%d %d: %lf %lf\n",i,j,dp[i][j][0],dp[i][j][1]);
			}
		}
		printf("%.10lf\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 1768kb

input:

2
4
0 0
1 0
1 1
0 1
3
1 3
2 4
3 4
4
0 0
1 0
1 1
0 1
4
1 4
4 3
3 2
2 1

output:

2.4142135624
3.0000000000

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 7ms
memory: 1796kb

input:

450
7
0 0
260338181 86092533
323066179 107441010
424697382 278447352
71444106 1000000000
-575302618 804979842
-258577414 97804732
20
2 3
2 5
1 3
7 4
2 1
5 3
6 2
7 5
4 2
3 6
1 7
5 6
4 6
4 5
3 4
7 2
6 1
1 5
7 6
4 1
5
0 0
713930457 800419774
94147955 958520832
-286069543 1000000000
-262432976 698118841...

output:

4765927085.1971368790
3445280472.4719648361
4807.7443030665
3190.4269732301
4345171440.2616090775
6514.4581109935
3773167316.2427730560
2276985.1357878428
1033.2264998537
2035605.4896589201
5547331390.4723348618
0.0000000000
2480.5999624696
2348460308.0295076370
7779.5832170821
4517152358.3733148575...

result:

ok 450 numbers

Test #3:

score: 0
Accepted
time: 4294ms
memory: 4280kb

input:

10
295
0 0
14682701 503060
25046284 1037424
36405162 1792084
39349419 2119133
68531516 5963501
88143287 8803232
105612921 11584151
110634846 12446595
115510397 13365788
123709362 15371938
138667321 19292100
143732922 20680197
152527267 23117317
161336760 25663342
175610584 29864225
179534317 3102751...

output:

138692526440.2213134766
142741536635.0141296387
210677906142.0534362793
44669007984.5861892700
143288343239.6969299316
7617016839.5704250336
49984226404.8773727417
199989775093.7639160156
206539582580.7242736816
45567211025.8372497559

result:

ok 10 numbers