2022“杭电杯”中国大学生算法设计超级联赛(1)K、L

Random

可知所有的概率都是\frac{1}{2},那么可以假设所有的数都取到\frac{1}{2},然后再进行操作,可知期望就是(n-m)/2,求2的逆元

AC代码:

#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using LL = long long;
//head
const LL mod = 1e9 + 7;
LL qp(LL a, LL b) {
    LL res = 1;
    for (; b; b >>= 1, a = a * a % mod) {
        if (b & 1) {
            res = res * a % mod;
        }
    }
    return res % mod;
}
void Solve() {
    LL n, m;
    cin >> n >> m;
    cout << (n - m) * qp(2ll, mod - 2) % mod << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    rep (i, 0, T) {
        Solve();
    }

    return 0;
}

Alice and Bob

由题意知,两个i+1合并出一个i,那么可以倒着做,看能否得出0

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

void Solve() {
    int n;
    cin >> n;
    vector<LL> a(n + 1);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i > 0; i--) {
        a[i - 1] += a[i] / 2;
    }
    if (a[0]) {
        cout << "Alice\n";
    }
    else {
        cout << "Bob\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
         Solve();
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值