QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282853#7753. Energy Distributiongrass8cowWA 0ms3984kbC++171.1kb2023-12-13 11:29:402023-12-13 11:29:40

Judging History

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

  • [2024-10-31 10:22:30]
  • hack成功,自动添加数据
  • (/hack/1089)
  • [2023-12-13 11:29:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3984kb
  • [2023-12-13 11:29:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-7;
double a[15][15],w[15][15],xd[15];
double sol(int n){
	for(int i=1;i<n;i++){
		a[i][n+1]=0;
		for(int j=1;j<=n;j++)a[i][j]=w[n][j]-w[i][j];
	}
	for(int i=1;i<=n;i++)a[n][i]=1;
	a[n][n+1]=1;
	for(int j=1;j<=n;j++){
		int p=j;
		for(int i=j+1;i<=n;i++)if(fabs(a[p][j])<fabs(a[i][j]))p=i;
		for(int i=1;i<=n+1;i++)swap(a[p][i],a[j][i]);
		if(fabs(a[j][j])<1e-8){printf("No Solution");return 0;}
		for(int i=1;i<=n;i++)if(j!=i){
			double tp=a[i][j]/a[j][j];
			for(int k=j+1;k<=n+1;k++)a[i][k]-=a[j][k]*tp;
		}
	}
	for(int i=1;i<=n;i++){
		xd[i]=a[i][n+1]/a[i][i];
		if(xd[i]+eps<0)return 0;
	}
	double su=0;
	for(int i=1;i<n;i++)for(int j=i+1;j<=n;j++)
	su+=w[i][j]*xd[i]*xd[j];
	return su;
}
double X[10][10];
int n,bt[10];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>X[i][j];
	double ans=0;
	for(int s=1;s<(1<<n);s++){
		int e=0;
		for(int i=0;i<n;i++)if((s>>i)&1)bt[e++]=i;
		for(int i=0;i<e;i++)for(int j=0;j<e;j++)w[i+1][j+1]=X[bt[i]][bt[j]];
		ans=max(ans,sol(e));
	}
	return printf("%.8lf",ans),0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 1
1 0

output:

0.25000000

result:

ok found '0.2500000', expected '0.2500000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

3
0 2 1
2 0 2
1 2 0

output:

0.57142857

result:

ok found '0.5714286', expected '0.5714290', error '0.0000004'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3
0 1 2
1 0 1
2 1 0

output:

0.50000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3984kb

input:

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

output:

No SolutionNo Solution0.75000000

result:

wrong output format Expected double, but "No" found