QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#262257 | #7753. Energy Distribution | proven# | WA | 1ms | 3756kb | C++11 | 2.6kb | 2023-11-23 17:12:51 | 2023-11-23 17:12:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double eps = 1e-10;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3708kb
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: 3572kb
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: 3588kb
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: 3756kb
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'