QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#38380#1182. LighthouseswyhaoWA 1ms1840kbC++1.7kb2022-07-05 12:58:222022-07-05 12:58:24

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 12:58:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1840kb
  • [2022-07-05 12:58:22]
  • 提交

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+n)%n;j=(j%n+n)%n;
	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);
		for(int i=1,x,y;i<=m;i++){
			scanf("%d%d",&x,&y);
			add(++cnt,x,y);
			add(++cnt,y,x);
		}
		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("%.10lf\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 1840kb

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
2.4142135624

result:

wrong answer 2nd numbers differ - expected: '3.0000000', found: '2.4142136', error = '0.1952621'