可知所有的概率都是,那么可以假设所有的数都取到,然后再进行操作,可知期望就是(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; }
由题意知,两个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; }
2022“杭电杯”中国大学生算法设计超级联赛(1)K、L
于 2022-08-02 10:27:15 首次发布