2022“杭电杯”中国大学生算法设计超级联赛(9)
[题目链接](Search Result (hdu.edu.cn))
J Sum Plus Product
题目大意
一共有n个数,每次随机选两个数a, b合并成为ab+ a + b,直到剩下一个数为止。求剩下数字的期望。
题解
假设取出数字a-1和b-1,可以合并为ab-1。
现在假设有数字a-1、b-1、c-1,合并结果一定为abc-1。
由此可得,答案为((a1+1)(a2+1)…(an+1))-1。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 5;
const ll mod = 998244353;
ll t, n, x, res;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--)
{
cin >> n;
res = 1;
for (int i = 1; i <= n; i++)
{
cin >> x;
res = (res * (x + 1)) % mod;
}
cout << (res - 1 + mod) % mod << endl;
}
return 0;
}
C Fast Bubble Sort
题目大意
给定一个长度为n的数组A,定义B(A)表示对A进行一次冒泡循环之后得到的数组。现有一种操作,可以将[l,r]区间的数字左移或右移一位。
现有一个长度为n的排列P,以及q组询问。每一组询问,求将P[l,r]变成B(P [l, r])所需的最小操作数。
题解
代码
H Shortest Path in GCD Graph
题目大意
给定n个点的完全图,两个点之间的距离为它们的gcd(i,j),q次询问两个点之间的最短路以及方案数。
题解
代码
太菜了,时间不够,先补一道最简单的QWQ。