QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23792#1777. Fortune From Follygalaxias#WA 2ms3776kbC++111.4kb2022-03-19 14:41:402022-04-30 04:08:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 04:08:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3776kb
  • [2022-03-19 14:41:40]
  • 提交

answer

#include <bits/stdc++.h>

#define db double

const db eps = 1e-6 ;
const int MAX_N = 100 + 10 ;

int n , m , k ;
db p , A[MAX_N][MAX_N] ;
bool ed[MAX_N] , sam[MAX_N] ;

void gauss() {
    for (int i = 0 ; i < m ; ++i) {
        for (int j = i + 1 ; j < m ; ++j)
            if (abs(A[i][i]) < abs(A[j][i])) for (int k = 0 ; k <= m ; ++k) std::swap(A[i][k] , A[j][k]) ;

        for (int j = i + 1 ; j < m ; ++j) {
            db xs = A[j][i] / A[i][i] ;
            for (int k = i ; k <= m ; ++k) A[j][k] -= xs * A[i][k] ;
        }
    }

    for (int i = m - 1 ; i >= 0 ; --i) {
        for (int j = i + 1 ; j < m ; ++j) A[i][m] -= A[j][m] * A[i][j] ;
        if (abs(A[i][i]) > eps) A[i][m] /= A[i][i] ;
        else A[i][m] = 0 ;
    }
}

int main() {
    scanf("%d %d %lf" , &n , &k , &p) ;

    m = (1 << n) ;
    for (int i = 0 ; i < m ; ++i) {
        int cnt = 0 ;
        for (int j = 0 ; j < n ; ++j) if ((1 << j) & i) ++cnt ;

        if (cnt >= k) ed[i] = 1 ;
        else if (cnt == k) sam[i] = 1 ;
    }

    for (int i = 0 ; i < m ; ++i) {
        A[i][i] = 1 ;
        if (sam[i]) A[i][m] = 1 ;
        if (ed[i]) continue ;

        for (int j = 0 ; j < 2 ; ++j) {
            int ni = (i << 1) & (m - 1) | j ;

            A[i][m] = 1 ;
            if (j) A[i][ni] -= p ;
            else A[i][ni] -= 1 - p ;
        }
    }
    gauss() ;
    printf("%0.7lf\n" , A[0][m]) ;

    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3776kb

input:

2 1 0.0006

output:

0.0000000

result:

wrong answer 1st numbers differ - expected: '1666.6666667', found: '0.0000000', error = '1.0000000'