QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638845#7753. Energy DistributionPandaGhostWA 0ms3952kbC++171.6kb2024-10-13 17:03:052024-10-13 17:03:07

Judging History

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

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

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPFI(x) freopen(#x".in", "r", stdin);\
                freopen(#x".out", "w", stdout)
#define REP(i, a, b) for(int i=(a); i<=(b); ++i)
#define REPd(i, a, b) for(int i=(a); i>=(b); --i)
inline ll rd(){
    ll r=0, k=1; char c=0; while(!isdigit(c=getchar())) if(c=='-') k=-k;
    while(isdigit(c)) r=r*10+c-'0', c=getchar(); return r*k;
}
const int N=110;
ll n, w[N][N];
double a[N][N], b[N];
bool check(double lmd){
    REP(i, 1, n){
        REP(j, 1, n) a[i][j]=w[i][j];
        b[i]=lmd;
    }
    REP(i, 1, n){
        int t=i;
        REP(j, i+1, n) if(abs(a[j][i])>1e-7&&(abs(a[t][i])>abs(a[j][i])||abs(a[t][i])<1e-7)) t=j;
        REP(j, i, n) swap(a[t][j], a[i][j]);
        if(abs(a[i][i])<1e-7){
            puts("No Solution");
            return 0;
        }
        swap(b[t], b[i]);
        double e=a[i][i];
        REP(j, i, n) a[i][j]/=e;
        b[i]/=e;
        REP(j, i+1, n){
            double d=a[j][i];
            REP(k, i, n) a[j][k]-=d*a[i][k];
            b[j]-=d*b[i];
        }
    }
    REPd(i, n, 1) REP(j, 1, i-1) b[j]-=a[j][i]*b[i], a[j][i]=0;
    double sum=0;
    REP(i, 1, n) sum+=b[i];
    return sum<1;
}
int main(){
    //OPFI(test);
    n=rd();
    REP(i, 1, n)
        REP(j, 1, n)
            w[i][j]=rd();
    
    double l=0, r=1e9;
    while(r-l>1e-8){
        double mid=(l+r)/2;
        if(check(mid)){
            l=mid;
        }else{
            r=mid;
        }
    }
    double ans=0;
    REP(i, 1, n) REP(j, i+1, n) ans+=b[i]*b[j]*w[i][j];
    printf("%.10f\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
0 1
1 0

output:

0.2500000067

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.5714285778

result:

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

Test #3:

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

input:

3
0 1 2
1 0 1
2 1 0

output:

0.5000000064

result:

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

Test #4:

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

input:

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

output:

0.4285714351

result:

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