# 计蒜客信息学赛前 CSP-S2 模拟赛 2

## $A$

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 1000000;

int n, head[N + 50], num, dp[N + 50];

template <class T>
{
x = 0; int p = 0; char st = getchar();
while (st < '0' || st > '9') p = (st == '-'), st = getchar();
while (st >= '0' && st <= '9') x = (x << 1) + (x << 3) + st - '0', st = getchar();
x = p ? -x : x;
return;
}

template <class T>
void Print(T x)
{
if (x > 9) Print(x / 10);
putchar(x % 10 + '0');
return;
}

void File()
{
freopen("node.in", "r", stdin);
freopen("node.out", "w", stdout);
return;
}

struct Node
{
int next, to, dis;
} edge[N * 2 + 50];

void Addedge(int u, int v, int w)
{
return;
}

void Dfs(int x, int fa, int fadis)
{
for (int i = head[x]; i; i = edge[i].next)
{
int v = edge[i].to;
if (v == fa) continue;
maxx = max(maxx, edge[i].dis);
Dfs(v, x, edge[i].dis);
}
dp[x] = maxx;
return;
}

int main()
{
//	File();
for (int i = 1, u, v, w; i <= n - 1; i++)
{
}
Dfs(1, 0, 0);
int pos = 1;
for (int i = 2; i <= n; i++) if (dp[i] < dp[pos]) pos = i;
printf("%d", pos);
return 0;
}


## $B$

$\sum_{p = 1}^{min(k, m - d)} \frac{\binom{m - 1}{p - 1} \binom{k - 1}{p - 1} \times m! \times k! \times n}{p}$

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 1000000;
const int MOD = 998244353;

template <class T>
{
x = 0; int p = 0; char st = getchar();
while (st < '0' || st > '9') p = (st == '-'), st = getchar();
while (st >= '0' && st <= '9') x = (x << 1) + (x << 3) + st - '0', st = getchar();
x = p ? -x : x;
return;
}

template <class T>
void Print(T x)
{
if (x > 9) Print(x / 10);
putchar(x % 10 + '0');
return;
}

int jc[N + 50], divjc[N + 50], n, k, d, div[N + 50];

int Zh(int n, int m)
{
return 1LL * jc[n] * divjc[n - m] % MOD * divjc[m] % MOD;
}

int Ksm(int a, int b)
{
int tmp = 1;
while (b)
{
if (b & 1) tmp = 1LL * tmp * a % MOD;
a = 1LL * a * a % MOD;
b >>= 1;
}
return tmp;
}

void File()
{
freopen("ring.in", "r", stdin);
freopen("ring.out", "w", stdout);
return;
}

int main()
{
//	File();
int t;
jc[0] = 1;
for (int i = 1; i <= N; i++) jc[i] = 1LL * jc[i - 1] * i % MOD;
divjc[N] = Ksm(jc[N], MOD - 2);
for (int i = N - 1; i >= 0; i--) div[i + 1] = 1LL * divjc[i + 1] * jc[i] % MOD, divjc[i] = 1LL * divjc[i + 1] * (i + 1) % MOD;
divjc[0] = div[0] = 1;
while (t--)
{
int m = n - k, ans = 0;
for (int i = 1; i <= m - d; i++)
ans = (0LL + ans + 1LL * Zh(m - 1, i - 1) * Zh(k, i - 1) % MOD * div[i] % MOD) % MOD;
ans = 1LL * ans * n %MOD * jc[m] % MOD * jc[k] % MOD;
printf("%d\n", ans);
}
return 0;
}

/*
1
4 2 1

16
*/


## $D$

posted @ 2020-10-18 19:33  Tian-Xing  阅读(210)  评论(0编辑  收藏  举报