QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#23805#1777. Fortune From Follygalaxias#WA 3ms3944kbC++111.3kb2022-03-19 15:24:352022-04-30 04:10:03

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:10:03]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3944kb
  • [2022-03-19 15:24:35]
  • 提交

answer

#include <bits/stdc++.h>

#define db long double

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

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

void gauss() {
    for (int i = 0 ; i < m ; ++i) {
		int r = i ;
		for (int j = i + 1 ; j < m ; ++j) if (fabs(A[r][i]) - fabs(A[j][i]) < eps) r = j ;
		if (r != i) for (int j = 0 ; j <= m ; ++j) std::swap(A[r][j] , A[i][j]) ;

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

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

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 ;
    }

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

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

            if (j) A[i][ni] -= p ;
            else A[i][ni] -= 1 - p ;
        }
    }
    gauss() ;

    printf("%0.8Lf\n" , A[0][m]) ;

    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3944kb

input:

2 1 0.0006

output:

1666.66666667

result:

ok found '1666.6666667', expected '1666.6666667', error '0.0000000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3788kb

input:

2 1 0.0043

output:

232.55813953

result:

ok found '232.5581395', expected '232.5581395', error '0.0000000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3728kb

input:

2 1 0.4202

output:

2.37981913

result:

ok found '2.3798191', expected '2.3798191', error '0.0000000'

Test #4:

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

input:

2 1 0.6729

output:

1.48610492

result:

ok found '1.4861049', expected '1.4861049', error '0.0000000'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3724kb

input:

2 1 0.9925

output:

1.00755668

result:

ok found '1.0075567', expected '1.0075567', error '0.0000000'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3924kb

input:

2 1 0.9999

output:

1.00010001

result:

ok found '1.0001000', expected '1.0001000', error '0.0000000'

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 3924kb

input:

2 2 0.0006

output:

-nan

result:

wrong output format Expected double, but "-nan" found