QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262259#7753. Energy Distributionproven#WA 0ms3952kbC++112.6kb2023-11-23 17:13:442023-11-23 17:13:45

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const double eps = 1e-18;
const int N = 20;
int n, nn;
double a[N][N];
double b[N][N];
int gauss() {
    int c, r;
    for(c = 0, r = 0; c < n; c++) {
        int t = r;
        for(int i = r; i < n; i++) {
            if(fabs(a[i][c]) > fabs(a[t][c]))
                t = i;
        }
        if(fabs(a[t][c]) < eps) continue;
        for(int i = c; i <= n; i++) {
            swap(a[t][i], a[r][i]);
        }
        for(int i = n; i >= c; i--) {
            a[r][i] /= a[r][c];
        }
        for(int i = r + 1; i < n; i++) {
            if(fabs(a[i][c]) > eps) {
                for(int j = n; j >= c; j--) {
                    a[i][j] -= a[r][j] * a[i][c];
                }
            }
        }
        r++;
    }
    for(int i = n - 1; i >= 0; i--) {
        for(int j = i + 1; j < n; j++) {
            a[i][n] -= a[i][j] * a[j][n];
        }
    }
    if(r < n) {
        for(int i = r; i < n; i++) {
            if(fabs(a[i][n]) > eps)
                return 2;
        }
        return 1;
    }
    return 0;
}

void solve() {
    cin >> nn;
    for(int i = 0; i < nn; i++) {
        for(int j = 0; j < nn; j++) {
            cin >> a[i][j];
            b[i + 1][j + 1] = a[i][j];
        }
    }
    //最后一行填n个1
    for(int i = 0; i < nn; i++) {
        a[nn][i] = 1;
    }
    n = nn + 1;
    //每一行第n - 1列填lamda的系数1,最后一行(第n行)填0
    for(int i = 0; i <= n - 1; i++) {
        if(i != n - 1) {
            a[i][n - 1] = 1;
        }
        else a[i][n - 1] = 0;
    }
    //每一行第n列填常数项,前n行填0
    for(int i = 0; i <= n - 1; i++) {
        if(i != n - 1)
            a[i][n] = 0;
        else
            a[i][n] = 1;
    }
//    for(int i = 0; i < n; i++) {
//        for(int j = 0; j < n + 1; j++) {
//            cout << a[i][j] << " ";
//        }
//        cout << endl;
//    }
    int t = gauss();
    vector<double> e(n + 1);
    if(t == 0) {
        for(int i = 0; i < n; i++) {
//            cout << a[i][n] << endl;
            e[i + 1] = a[i][n];
        }
    }
    double ans = 0;
    for(int i = 1; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            ans += e[i] * e[j] * b[i][j];
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2
0 1
1 0

output:

0.2500000000

result:

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

Test #2:

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

input:

3
0 2 1
2 0 2
1 2 0

output:

0.5714285714

result:

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

Test #3:

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

input:

3
0 1 2
1 0 1
2 1 0

output:

0.5000000000

result:

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

Test #4:

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

input:

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

output:

0.4285714286

result:

wrong answer 1st numbers differ - expected: '0.7500000', found: '0.4285714', error = '0.3214286'