QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#638698 | #7753. Energy Distribution | ShwStone | WA | 153ms | 4164kb | C++14 | 1.5kb | 2024-10-13 16:38:51 | 2024-10-13 16:38:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN(15), MAXEPOCH(1e6);
int n;
double A[MAXN][MAXN], M[MAXN][MAXN];
double u[MAXN], v[MAXN];
double du[MAXN], dv[MAXN];
double myexp(double x) {
if (x > 1e18) return 1e18;
else if (x < -1e18) return 1e-18;
return exp(x);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%lf", &A[i][j]);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
M[i][j] = A[i][j];
}
}
double begin_rate(10. / n), end_rate(.001);
double rate = begin_rate;
for (int epoch = 0; epoch < MAXEPOCH; epoch++) {
rate -= (begin_rate - end_rate) / MAXEPOCH;
double sumv = 0;
for (int i = 1; i <= n; i++) sumv += myexp(v[i]);
for (int i = 1; i <= n; i++) u[i] = myexp(v[i]) / sumv;
for (int i = 1; i <= n; i++) {
du[i] = 0;
for (int j = 1; j <= n; j++) {
du[i] += M[i][j] * u[j];
}
}
for (int i = 1; i <= n; i++) {
dv[i] = 0;
for (int j = 1; j <= n; j++) {
if (i == j) dv[i] += du[j] * u[j] * (1 - u[j]);
else dv[i] -= du[j] * u[i] * u[j];
}
}
for (int i = 1; i <= n; i++) v[i] += rate * dv[i];
}
double sumv = 0;
for (int i = 1; i <= n; i++) sumv += exp(v[i]);
for (int i = 1; i <= n; i++) u[i] = exp(v[i]) / sumv;
double ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
ans += u[i] * u[j] * A[i][j];
}
}
printf("%.9lf\n", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 33ms
memory: 4020kb
input:
2 0 1 1 0
output:
0.250000000
result:
ok found '0.2500000', expected '0.2500000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 58ms
memory: 3964kb
input:
3 0 2 1 2 0 2 1 2 0
output:
0.571428571
result:
ok found '0.5714286', expected '0.5714290', error '0.0000004'
Test #3:
score: 0
Accepted
time: 58ms
memory: 4164kb
input:
3 0 1 2 1 0 1 2 1 0
output:
0.499999900
result:
ok found '0.4999999', expected '0.5000000', error '0.0000001'
Test #4:
score: 0
Accepted
time: 74ms
memory: 4108kb
input:
4 0 3 1 0 3 0 1 0 1 1 0 2 0 0 2 0
output:
0.749999200
result:
ok found '0.7499992', expected '0.7500000', error '0.0000008'
Test #5:
score: 0
Accepted
time: 93ms
memory: 4068kb
input:
5 0 0 0 4 4 0 0 2 0 4 0 2 0 2 0 4 0 2 0 0 4 4 0 0 0
output:
0.999999300
result:
ok found '0.9999993', expected '1.0000000', error '0.0000007'
Test #6:
score: 0
Accepted
time: 125ms
memory: 4088kb
input:
6 0 9 5 5 10 6 9 0 0 0 0 1 5 0 0 0 3 0 5 0 0 0 10 5 10 0 3 10 0 0 6 1 0 5 0 0
output:
2.857140922
result:
ok found '2.8571409', expected '2.8571430', error '0.0000007'
Test #7:
score: -100
Wrong Answer
time: 153ms
memory: 4092kb
input:
7 0 0 0 0 50 10 45 0 0 0 0 0 3 1 0 0 0 0 0 4 16 0 0 0 0 44 0 0 50 0 0 44 0 37 6 10 3 4 0 37 0 2 45 1 16 0 6 2 0
output:
12.511570974
result:
wrong answer 1st numbers differ - expected: '12.5115850', found: '12.5115710', error = '0.0000011'