20140328

B

F[i, j] |= F[i - 1, j - a[k]] 表示i桶油,j距离可行与否

对X的处理。不接受编译开关

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

//Love lemon_TsyD
//Miss lydrainbowcat
//By ITX351

const int MAXN = 1111, MAXL = 1111, T = 4;
int F[T + 3][MAXL]; int a[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int Test;
    scanf("%d", &Test);
    
    while (Test--)
    {
        memset(F, 0, sizeof(F));
        
        int L, X, N;
        scanf("%d%d%d", &L, &X, &N);
        
        for (int i = 1; i <= N; i++)
            scanf("%d", a + i);
        
        F[0][X] = true;
        for (int i = 1; i <= T; i++)
            for (int j = 0; j <= L; j++)
            {
                for (int k = 1; k <= N; k++)
                    if (j - a[k] >= 0)
                        F[i][j] |= F[i - 1][j - a[k]];
            }
        
        printf("%s\n", F[T][L] ? "Yes" : "No");
    }
    return 0;
}


C

结果只与L、H能整除多少个2的数量奇偶性有关


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

//Love lemon_TsyD
//Miss lydrainbowcat
//By ITX351

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int Test;
    scanf("%d", &Test);
    
    while (Test--)
    {
        int L, H;
        scanf("%d%d", &L, &H);
        
        int ans = 0;
        while (!(L & 1))
        {
            L >>= 1;
            ans++;
        }
        while (!(H & 1))
        {
            H >>= 1;
            ans++;
        }
        printf("%s\n", ans & 1 ? "Adidas loses" : "Adivon prevails");
    }

    return 0;
}

F

连续击中和不连续的混沌到一起考虑……每次击中后的期望积分都是上一次的积分加一,再乘以概率

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

//Love lemon_TsyD
//Miss lydrainbowcat
//By ITX351

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int Test;
    scanf("%d", &Test);
    
    while (Test--)
    {
        int L; double P;
        scanf("%d%lf", &L, &P);
        
        double pre = .0, ans = .0;
        for (int i = 1; i <= L; i++)
        {
            pre = (pre + 1.0) * P;
            ans += pre;
        }
        printf("%.6lf\n", ans);
    }

    return 0;
}


H

一正一反的概率是p(1-p),期望除一。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

//Love lemon_TsyD
//Miss lydrainbowcat
//By ITX351

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int Test;
    scanf("%d", &Test);
    
    while (Test--)
    {
        double p;
        scanf("%lf", &p);
        
        double ans = 1.0 / (p * (1 - p));
        printf("%.2lf\n", ans);
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值