[Contest]2017 ACM/ICPC Asia Regional Xian Online(施工中...)

A. Tree

题意

题解

代码


B. Coin

题意

给定抛一枚硬币向上的概率是$\frac{q}{p}(\frac{q}{p}\leq \frac{1}{2})$,求抛$k$次向上次数为偶数的概率。

题解

首先$res=\sum_{i=0}{\frac{k}{2}}{\binom{k}{2i}(\frac{q}{p})(1-\frac{q}{p})^{k-2i}}$。
然后我们发现它其实是$f(x)=(\frac{q}{p}x+
(1-\frac{q}{p}))k$的偶数项之和,故$res=\frac{f(-1)+f(1)}{2}=\frac{1}{2}(1-(\frac{p-2q}{p})k)$。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll Q = 1e9+7;

inline ll read() {
    ll s = 1, x = 0; char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') s = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return s * x;
}

inline ll power(ll x, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret *= x, ret %= Q;
        x *= x, x %= Q;
        n >>= 1;
    }
    return ret;
}

int main() {
    ll T = read();
    while (T--) {
        ll p = read(), q = read(), k = read();
        printf("%lld\n", ((power(p, k) + power(p - 2ll * q, k)) % Q * power(2ll, Q - 2)) % Q * power(power(p, k), Q - 2) % Q);
    }
    return 0;
}

C. Sum

题意

给定一个正整数$x$,求一个位数不超过$2000$的正整数$k$,使得$k\times x$的十进制位之和是$233$的倍数。

题解

我们考虑把$x$重复$233$次之后的十进制位之和一定是$233$的倍数,而$x\leq 106$,只要让$k={107}+{107}2+{107}3+...+{107}$即可。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int read() {
    int s = 1, x = 0; char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') s = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return s * x;
}

int main() {
    int T = read();
    while (T--) {
        int x = read();
        for (int i = 1; i <= 233; i++) printf("10000000");
        printf("\n");
    }
    return 0;
}

D. Brain-baffling Game

题意

题解

代码


E. Maximum Flow

题意

题解

代码


F. Trig Function

题意

求$\cos nx$展开式中$\cos^m x$项的系数。

题解

当$n$和$m$奇偶性相同时,$\cos^m x$项的系数为$(-1)^{\frac{n-m}{2}}\times\frac{n\times(n+m-2)!!}{m!(n-m)!!}$,除法改成乘逆元即可。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Q = 998244353;

inline ll power(ll x, ll n) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret *= x, ret %= Q;
        x *= x, x %= Q;
        n >>= 1;
    }
    return ret;
}

inline ll f(ll n, ll m) {
    if (n < m) return 0;
    if ((n % 2) ^ (m % 2) == 1) return 0;
    ll sgn = ((n - m) / 2) % 2 ? -1 : 1, abs = n;
    if (m == 0) 
        abs /= n, abs %= Q;
    else {
        for (ll k = n - m + 2; k <= n + m - 2; k += 2) abs *= k, abs %= Q;
        for (ll k = 2; k <= m; k++) abs *= power(k, Q - 2), abs %= Q;
    }
    ll ret = (sgn * abs + Q) % Q;
    return ret;
}

int main() {
    ll n, m;  
    while (~scanf("%lld %lld", &n, &m)) {
        printf("%lld\n", f(n, m));
    }
    return 0;
}

G. Xor

题意

题解

代码


H. Music

题意

题解

代码


I. Barty's Computer

题意

题解

代码


J. Easy Problem

题意

题解

代码


posted @ 2017-09-17 00:40  jstztzy  阅读(221)  评论(0编辑  收藏  举报