Solved Problem ID Title Ratio (Accepted / Submitted)
1001 Arithmetic Subsequence 18.04% (221/1225)
1002 Conquest of Masters Tour 7.07% (7/99)
1003 Fast Bubble Sort 30.05% (317/1055)
1004 If You Can’t Beat Them, Join Them! 18.50% (32/173)
1005 Leapfrogger 26.32% (5/19)
1006 Mario Party 14.61% (70/479)
1007 Matryoshka Doll 48.43% (323/667)
1008 Shortest Path in GCD Graph 12.01% (484/4029)
1009 Simple Math 4 18.75% (21/112)
1010 Sum Plus Product 77.63% (899/1158)
1011 The Alchemist of the Discrete Mathematics 5.63% (4/71)
Sum Plus Product
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 35 Accepted Submission(s): 28
Problem Description
triplea has a box with n(n≥1) balls inside, where on each of the balls there is an integer written. When there are at least two balls inside the box, triplea will do the following operation repeatedly:
The operation will end when there is only one ball in the box. triplea wonders, what is the expected value of the number written on the last ball? He gets the answer immediately, and leaves this as an exercise for the reader, namely, you.
Input
The first line of input consists of an integer T(1≤T≤20), denoting the number of test cases.
For each test case, the first line of input consists of an integer n(1≤n≤500), denoting the initial number of balls inside the box.
The next line contains n integers a1,a2,…,an(0≤ai<998244353), denoting the number written on each ball in the box, initially.
Output
For each test case, output an integer in one line, denoting the expected value of the number written on the last ball. Under the input constraints of this problem, it can be shown that the answer can be written as PQ, where P and Q are coprime integers and Q≢0(mod998244353). You need to output P⋅Q−1(mod998244353) as an answer, where Q−1 is the modular inverse of Q with respect to 998244353.
Sample Input
2
2
2 2
10
1 2 4 8 16 32 64 128 256 512
Sample Output
8
579063023
Source
2022“杭电杯”中国大学生算法设计超级联赛(9)
题意:
思路:
#include
using namespace std;
typedef long long LL;
const LL maxn = 510, mod = 998244353;
int main(){
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--){
int n; cin>>n;
LL x, y; cin>>x;
for(int i = 2; i <= n; i++){
cin>>y; x = (x+y+x*y%mod)%mod;
}
cout<<x<<"\n";
}
return 0;
}
Shortest Path in GCD Graph
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 619 Accepted Submission(s): 167
Problem Description You need to answer q queries. In each query, given two vertices u,v, you need to answer the length of the shortest path as well as the number of shortest paths between u,v. Since the number of shortest paths may be too large, you only need to output it modulo 998244353. Input Then q lines follow, where each line contains two integers u,v(1≤u,v≤n,u≠v), denoting a query between u and v. Output Sample Input Sample Output Source 题意: 思路: Matryoshka Doll Problem Description A matryoshka of size i can be put into another matryoshka of size j if and only if j−i≥r, where r is some given integer parameter. zyb wishes to divide all n matryoshka dolls into k groups, such that one can form a nested matryoshka doll in each group, where a group of matryoshka dolls with indices c1,c2,…,cm (1≤c1 zyb wants to know how many ways there are to divide the n dolls into k groups satisfying the requirement above. Note that divisions such as {{1,2},{3,4}} and {{3,4},{1,2}} are considered the same way. As the answer may be too large, you only need to output the answer modulo 998244353. Input For each test case, the first line contains three integers n,k,r(1≤k≤n≤5000,1≤r≤109), denoting the number of matryoshka dolls, the number of groups zyb wants to divide into, and the parameter, respectively. The next line contains n integers a1,a2,…,an(1≤a1≤a2≤…≤an≤109), denoting the sizes of the matryoshka dolls. It is guaranteed that ∑n≤50000 over all test cases. Output Sample Input Sample Output Source 题意: 思路: Fast Bubble Sort Problem Description You may perform the following operation any number (including zero) of times on the array A=(a1,a2,…,am): For example, if we cyclically shift the interval [1,4] of the array A=[1,2,3,4,5] to the right, the resulting array would be A′=[4,1,2,3,5]. You are now given a permutation P=(p1,p2,…,pn) of length n and you need to answer q independent queries of the following form: Input For each test case, the first line contains two integers n,q (1≤n,q≤105), denoting the length of permutation P and the number of queries, respectively. The second line contains n distinct integers p1,p2,…,pn (1≤pi≤n). Each of the following q lines contains two integers li,ri (1≤li≤ri≤n), denoting the parameters for the i-th query. Output Sample Input Sample Output Source 题意: 思路:
There is an edge-weighted complete graph Kn with n vertices, where vertices are labeled through 1,2,…,n.
For each 1≤i
The first line contains two integers n,q(2≤n≤107,1≤q≤50000), denoting the number vertices in the graph and the number of queries, respectively.
For each query, output one line contains two integers, denote the length and number of shortest path between given nodes, respectively. Note that only the number of shortest paths should be taken modulo 998244353.
6 2
4 5
3 6
1 1
2 2
2022“杭电杯”中国大学生算法设计超级联赛(9)//1008
#include//1008, 精简版(去掉了哈希, 快读,手写合并, 优化了容斥)
#include7.Matryoshka Doll
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 207 Accepted Submission(s): 117
zyb bought n matryoshka dolls during his visit to Moscow, with sizes a1,a2,…,an, respectively, sorting from smallest to largest.
The first line contains an integer T(1≤T≤20), denoting the number of test cases.
For each test case, output an integer in a line, denoting the answer taken modulo 998244353.
2
4 3 2
1 2 3 4
4 2 1
1 1 2 2
3
2
2022“杭电杯”中国大学生算法设计超级联赛(9)
转移时考虑第x个套娃放在前面的某一组(x-1,y),或者单独一组(x-1,y-1)。
即𝑑𝑝(𝑥,𝑦) = 𝑑𝑝(𝑥 − 1,𝑦 − 1) + 𝑑𝑝(𝑥 − 1,𝑦) · max{0,𝑦 − 𝑓 (𝑥)}, 𝑓(𝑥)表示满足1 ≤ 𝑧 < 𝑥且𝑎𝑥 − 𝑟 < 𝑎𝑧 ≤ 𝑎𝑥的𝑧的个数, 即y组中不能放入x进行转移的组的数量。
分成y组不需要知道每组的最大值,因为反正dp是考虑了所有情况的,肯定会包含那些不能进行转移的情况,只需要y把这些情况减掉就行了。//1007
#include3.Fast Bubble Sort
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 129 Accepted Submission(s): 61
Given an array A=(a1,a2,…,am) of length m, denote by array B(A) the output of a single iteration of bubble sort with input array A, i.e., the output of the following algorithm with input array A.
The first line contains an integer T(1≤T≤10) denote the number of test cases.
For each query of each test case, output an integer in one line, denoting the answer.
1
10 5
3 7 9 2 6 4 5 8 10 1
1 10
2 6
7 9
4 9
3 3
2
1
0
1
0
2022“杭电杯”中国大学生算法设计超级联赛(9)
即相当于对于给定区间,一次冒泡排序需要将所有逆序a[i]>a[i+1]的a[i]都移动到后面第一个大于它的数前方,答案为满足递增的局部最大值中间的数的个数。
对于每个固定的左端点𝑙,[𝑙, 𝑛]中从左到右的局部最大值可以通过单调栈维护,局部最大值插入/删除对于答案的影响可以用树状数组/线段树快速更新/求解。//1003
#include