# 2020百度之星程序设计大赛复赛

## A. Battle for Wosneth (Hdu 6838)

### 解题思路

$Bob$血量大于$1$时，设$Alice$命中一次$Bob$，自身血量变化的期望值为$x$,则（此处$p,q$为小数）

$x = p \times (1 - q) + ( 1 - p ) \times ( - q + x )$

$x = 1 - \frac{q}{p}$

$(m-1)\times x = (m - 1) ( 1 - \frac{q}{p})$

$Bob$剩下一滴血时，由于如果$Alice$命中他，则Bob不会反击，这是与上方的区别所在，设$Alice$命中Bob，自身血量变化值为$y$，则

$y = p \times 1 + (1 - p) \times (-q + y)$

$y = 1 - \frac{q}{p} + q$

$ans = (m-1) \times x + y = (1 - \frac{q}{p}) \times m + q$

$(1 - \frac{q}{p}) \times m - (-q) = (1 - \frac{q}{p}) \times m + q$

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

const LL mo = 998244353;

LL qpower(LL a, LL b)
{
LL qwq = 1;
while (b)
{
if (b & 1)
qwq = qwq * a % mo;
b >>= 1;
a = a * a % mo;
}
return qwq;
}

LL inv(LL x)
{
return qpower(x, mo - 2);
}

int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int kase;
cin >> kase;
for (int ii = 1; ii <= kase; ii++)
{
LL m, q, p;
cin >> m >> p >> q;
p = p * inv(100) % mo;
q = q * inv(100) % mo;
LL ans = ((1 - q * inv(p) % mo + mo) % mo * m % mo + q) % mo;
cout << ans << endl;
}
return 0;
}


## B. Binary Addition (Hdu 6839)

### 题目大意

• 将某一位与$1$异或
• 将其视为一个数，对它加一。其中最低位在最左边

### 解题思路

$num_0[i]$表示$S$串的前$i$个数中$0$的个数，$num_1[i]$表示$T$串的前$i$个数中$1$的个数，$cnt[i]$表示$S$$T$串的$[i..n]$中不同的数的个数。

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

template <typename T>
{
int s = 0, c = getchar();
x = 0;
while (isspace(c))
c = getchar();
if (c == 45)
s = 1, c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s)
x = -x;
}

template <typename T>
void write(T x, char c = ' ')
{
int b[40], l = 0;
if (x < 0)
putchar(45), x = -x;
while (x > 0)
b[l++] = x % 10, x /= 10;
if (!l)
putchar(48);
while (l)
putchar(b[--l] | 48);
putchar(c);
}

const int N = 1e5 + 8;

char s[N], t[N];

int n;

int cnt[N];

int num0[N];

int num1[N];

int qwq(int pos)
{
return num0[pos] + (s[pos + 1] == 1) + 1 + num1[pos] + (t[pos + 1] == 0) + cnt[pos + 2];
}

int main(void)
{
int kase;
for (int ii = 1; ii <= kase; ii++)
{
scanf("%s", s + 1);
scanf("%s", t + 1);
num0[0] = num1[0] = 0;
for (int i = 1; i <= n; ++i)
{
s[i] -= '0';
t[i] -= '0';
num0[i] = num0[i - 1] + (s[i] == 0);
num1[i] = num1[i - 1] + (t[i] == 1);
}
cnt[n + 1] = 0;
cnt[n + 2] = 0;
bool sign = false;
int cur = n;
for (int i = n; i >= 1; --i)
{
cnt[i] = cnt[i + 1] + (s[i] ^ t[i]);
}
int ans = cnt[1];
for (int i = 1; i <= n; ++i)
{
ans = min(ans, qwq(i));
}
write(ans, '\n');
}
return 0;
}


## C. Range k-th Maximum Query (Hdu 6840)

### 解题思路

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

template <typename T>
{
int s = 0, c = getchar();
x = 0;
while (isspace(c))
c = getchar();
if (c == 45)
s = 1, c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s)
x = -x;
}

template <typename T>
void write(T x, char c = ' ')
{
int b[40], l = 0;
if (x < 0)
putchar(45), x = -x;
while (x > 0)
b[l++] = x % 10, x /= 10;
if (!l)
putchar(48);
while (l)
putchar(b[--l] | 48);
putchar(c);
}

const int N = 1e5 + 8;

int n, k, l, d, r;

LL a[N];

LL solve(LL a[], int k)
{
LL ans = 0;
for (int i = k; i < d * k; ++i)
{
ans += a[i] * (1 + (l - k) * (i % k == 0));
}
ans += a[d * k] * min(r + 1, l - k + 1);
if (r > l - k)
{
for (int i = d * k + 1, yu = r - l + k; yu; ++i, --yu)
{
ans += a[i];
}
}
return ans;
}
int main(void)
{
int kase;
for (int ii = 1; ii <= kase; ii++)
{
for (int i = 1; i <= n; ++i)
{
}
sort(a + 1, a + 1 + n, greater<int>());
d = n / l;
r = n % l;
LL ans1 = solve(a, k);
sort(a + 1, a + 1 + n);
k = l - k + 1;
LL ans2 = solve(a, k);
printf("%lld %lld\n", ans1, ans2);
}
return 0;
}


qwq

### 解题思路

qwq

qwq


## E. Battle for Wosneth2 (Hdu 6842)

### 解题思路

• 移动到$(i-1, j-1)$的概率$a = \dfrac{pq}{1 - (1 - p)(1 - q)}$

• 移动到$(i, j - 1)$的概率$b = \dfrac{p(1-q)}{1 - (1 - p)(1 - q)}$

• 移动到$(i - 1, j)$的概率$c = \dfrac{q(1-p)}{1 - (1 - p)(1 - q)}$

$\sum\limits_{i = 0}^{n-1}\sum\limits_{x = 0}^{\min(i,m - 1)} C_{m - 1 + i -x}^{i - x} C_{m - 1} ^{x}a ^ {x} b ^ {m - 1 - x} c ^{i - x}$

\begin{aligned} &\sum\limits_{x = 0}^{\min(m-1,n-1)}\sum\limits_{i = 0}^{n - 1 - x} C_{m - 1 + i}^{i}C_{m - 1}^{x} a^{x}b^{m - 1 -x}c^{i} \\ &= \sum\limits_{x = 0}^{\min(m-1,n-1)}C_{m - 1}^{x} a^{x}b^{m - 1 -x}\sum\limits_{i = 0}^{n - 1 - x} C_{m - 1 + i}^{i}c^{i} \end{aligned}

$ans = d \times \sum\limits_{x = 0}^{\min(m-1,n-1)}C_{m - 1}^{x} a^{x}b^{m - 1 -x}S(n - 1 - x)$

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

template <typename T>
{
int s = 0, c = getchar();
x = 0;
while (isspace(c))
c = getchar();
if (c == 45)
s = 1, c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
if (s)
x = -x;
}

template <typename T>
void write(T x, char c = ' ')
{
int b[40], l = 0;
if (x < 0)
putchar(45), x = -x;
while (x > 0)
b[l++] = x % 10, x /= 10;
if (!l)
putchar(48);
while (l)
putchar(b[--l] | 48);
putchar(c);
}

const LL mo = 998244353;

const int N = 2e5 + 8;

int n, m;

LL jie[N], invjie[N];

LL sum[N];

LL p, q;

LL a, b, c, d;

LL inv100 = 828542813;

LL ans;

LL qpower(LL a, LL b)
{
LL qwq = 1;
while (b)
{
if (b & 1)
qwq = qwq * a % mo;
b >>= 1;
a = a * a % mo;
}
return qwq;
}

LL inv(LL x)
{
return qpower(x, mo - 2);
}

LL C(int n, int m)
{
if (n < m)
return 0;
return jie[n] * invjie[m] % mo * invjie[n - m] % mo;
}

int main(void)
{
int kase;
jie[0] = invjie[0] = 1;
for (int i = 1; i < N; ++i)
{
jie[i] = jie[i - 1] * i % mo;
invjie[i] = inv(jie[i]);
}
for (int ii = 1; ii <= kase; ii++)
{
p = p * inv100 % mo;
q = q * inv100 % mo;
d = inv((1 - (1 - p) * (1 - q) % mo + mo) % mo);
a = p * q % mo * d % mo;
b = p * ((1 - q + mo) % mo) % mo * d % mo;
c = q * ((1 - p + mo) % mo) % mo * d % mo;
sum[0] = 1;
LL tmp = c;
for (int i = 1; i < n; ++i)
{
sum[i] = (sum[i - 1] + tmp * C(m - 1 + i, i) % mo) % mo;
tmp = tmp * c % mo;
}
ans = 0;
LL qaq = 1;
// LL qbq = qpower(b, m - 1);
// LL invb = inv(b);
int up = min(m - 1, n - 1);
for (int i = 0; i <= up; ++i)
{
ans = (ans + qaq * qpower(b, m - i - 1) % mo * C(m - 1, i) % mo * sum[n - i - 1] % mo) % mo;
// ans = (ans + qaq * qbq % mo * C(m - 1, i) % mo * sum[n - i - 1] % mo) % mo;   // 0^0 = 1
qaq = qaq * a % mo;
// qbq = qbq * invb % mo;
}
ans = ans * p % mo * d % mo;
write(ans, '\n');
}
return 0;
}


## F. Query on the Tree (Hdu 6843)

qwq

### 解题思路

qwq

qwq


posted @ 2020-08-10 23:47  ~Lanly~  阅读(164)  评论(9编辑  收藏