QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#310878 | #7753. Energy Distribution | 275307894a# | WA | 0ms | 4048kb | C++14 | 1.6kb | 2024-01-21 19:19:27 | 2024-01-21 19:19:28 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=10+5,M=1.5e7+5,K=(1<<25)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,B[N][N],id[N],ih;
db ans,A[N][N],w[N];
int add(){
for(int i=1;i<=ih;i++) if(w[i]){
if(!A[i][i]) {Mc(A[i],w);return 1;}
db p=w[i]/A[i][i];
for(int j=i;j<=ih+1;j++) w[j]-=p*A[i][j];
}
if(A[ih+1]) return -1;
}
void calc(){
int i,j;
Me(A,0);
for(i=1;i<=ih;i++) w[i]=1;w[ih+1]=-1;if(add()==-1) return;
for(i=2;i<=ih;i++){
Me(w,0);
for(j=1;j<=ih;j++) w[j]=B[id[1]][id[j]]-B[id[i]][id[j]];
if(add()==-1) return;
}
for(i=ih;i;i--){
if(!A[i][i]){w[i]=0;continue;}
w[i]=-A[i][ih+1];
for(j=i+1;j<=ih;j++) w[i]-=w[j]*A[i][j];
w[i]/=A[i][i];
}
// for(i=1;i<=ih;i++) cerr<<w[i]<<' ';cerr<<'\n';
db tot=0;for(i=1;i<=ih;i++) for(j=i+1;j<=ih;j++) tot+=B[id[i]][id[j]]*w[i]*w[j];
ans=max(ans,tot);
}
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&B[i][j]);
for(i=1;i<(1<<n);i++){
ih=0;for(j=1;j<=n;j++) if(i>>j-1&1) id[++ih]=j;
calc();
}
printf("%.8lf\n",ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4024kb
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: 4048kb
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: 4032kb
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: 4040kb
input:
4 0 3 1 0 3 0 1 0 1 1 0 2 0 0 2 0
output:
1.00000000
result:
wrong answer 1st numbers differ - expected: '0.7500000', found: '1.0000000', error = '0.2500000'