想问下是不是输出格式的问题
查看原帖
想问下是不是输出格式的问题
322285
北京楼主2023/4/12 19:32

UVa 的题格式被卡见怪不怪了,但是这次真不知道是哪的问题,交了好多次都是 WA

当然也有可能是因为题目中说未定义的输入直接输出-1,但是题目好像又没有说未定义输入具体是指什么样的输入?

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2010;
long double C[N][N];
double p, q;

int main()
{
    for (int i = 0; i < N; ++i) C[i][0] = 1;
    for (int i = 1; i < N; ++i)
        for (int j = 1; j <= i; ++j)
             C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    
    int _n = 0;
    scanf("%lf%d", &p, &_n);
    while (true)
    {
        q = 1 - p;
        
        if (!_n) break;
        
        for (int i = 1; i <= _n; ++i)
        {
            int n, m;
            scanf("%d%d", &n, &m);
            
            long double P = 0;
            for (int i = 1; i <= m; ++i)
                P += C[n - 1 + m - i][n - 1] * pow(p, n) * pow(q, m - i);
            printf("%.5Lf\n%.0Lf\n", P, 2 * C[n + m][n] - 2);
        }
        
        scanf("%lf%d", &p, &_n);
        if (!_n) break;
        puts("");
    }
    return 0;
}
2023/4/12 19:32
加载中...