其他分享
首页 > 其他分享> > 省选测试18

省选测试18

作者:互联网

A 飞行棋

题目大意 : 走棋,问每个人获胜的概率是多少

Code

Show Code
#include <cstdio>
#include <cstring>

using namespace std;
const int N = 160;
const double eps = 1e-8;

int read(int x = 0, int f = 1, char c = getchar()) {
    for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
    for (; c >='0' && c <='9'; c = getchar()) x = x * 10 + c - '0';
    return x * f;
}

int n, m, t[N], a[N];
double f[2][N], s, q[N], p[N];

int main() {
    n = read(); m = read();
    if (m == 1) return puts("1"), 0;
    for (int i = 1; i <= n; ++i) 
        t[i] = read();
    for (int i = 1; i <= m; ++i) 
        a[i] = read(), q[i] = 1;// q[i] 表是当前第i个人不能到达n的概率
    for (int i = 1; i < 6; ++i)
        t[n+i] = t[n];
    s = f[0][n] = 1;//s 表示当前没有一个人能到达n的概率
    for (int i = 1; s > eps; i ^= 1) {
        memset(f[i], 0, sizeof(f[i]));
        for (int j = 1; j < n; ++j) {
            for (int k = 1; k <= 6; ++k)
                f[i][j] += f[i^1][t[j+k]];
            f[i][j] /= 6;
        }
        for (int j = 1; j <= m; ++j) {
            s /= q[j];
            p[j] += f[i][a[j]] * s;
            q[j] -= f[i][a[j]];
            s *= q[j];
        }
    }
    for (int i = 1; i <= m; ++i)
        printf("%.9lf\n", p[i]);
    return 0;
}

B 字符串难题 (Unaccepted)

题目大意 :

Code

Show Code

C 障碍雷达 (Unaccepted)

题目大意 :

Code

Show Code

标签:Code,题目,Show,省选,18,int,测试,大意,dp
来源: https://www.cnblogs.com/shawk/p/14386432.html