Solved Problem ID Title Ratio (Accepted / Submitted)
1001 Winner Prediction 14.38% (391/2719)
1002 Photos 23.83% (107/449)
1003 Wavy Tree 37.31% (670/1796)
1004 Average Replacement 15.13% (303/2003)
1005 Apples 30.95% (26/84)
1006 Triangle Rotation 30.00% (18/60)
1007 Even Tree Split 41.73% (782/1874)
1008 Minimum Diameter 18.52% (75/405)
1009 Painting Game 26.44% (588/2224)
1010 Tree 14.78% (17/115)
1011 Maximum Triangles 14.05% (17/121)
1012 Expected Inversions 10.66% (29/272)
Problem Description
You are given an undirected tree with nn nodes. It’s guaranteed that nn is even.
You are going to delete some of the edges (at least 11), and have to let each of the remaining connected components have an even number of vertices.
Calculate the number of ways to delete the edges that satisfy such constraints, modulo 998244353998244353.
Input
The first line contains an integer T(1 \leq T \leq 30)T(1≤T≤30) - the number of test cases.
The first line of each test case contains an integer n(1 \leq n \leq 10^5)n(1≤n≤10
5
) - the number of vertices on the tree.
The next n-1n−1 lines of each test case contain two integers u,v(1 \leq u,v \leq n)u,v(1≤u,v≤n), representing an edge between uu and vv.
It is guaranteed that the input graph is a tree with even number of vertices.
Output
For each test case, output the number of ways to delete the edges that satisfy such constraints in a single line, modulo 998244353998244353.
Sample Input
2
2
1 2
4
1 2
2 3
3 4
Sample Output
0
1
题意:
思路:
#include
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
typedef long long LL;
const LL maxn = 1e5+10, mod = 998244353;
vector<int>G[maxn];
LL ans = 1;
int siz[maxn];
void dfs2(int x, int f){
siz[x] = 1;
for(int y : G[x]){
if(y==f)continue;
dfs2(y,x);
siz[x] += siz[y];
}
}
void dfs(int x, int f, int d){
if(siz[x]%2==0 && x!=1){
ans = (ans*2)%mod;
}
for(int y : G[x]){
if(y==f)continue;
dfs(y,x,d+1);
}
}
int main(){
IOS;
int T; cin>>T;
while(T--){
int n; cin>>n;
for(int i = 1; i <= n; i++)G[i].clear(), siz[i] = 0;
ans = 1;
for(int i = 1; i <n; i++){
int u, v; cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs2(1,-1);
dfs(1,-1, 1);
cout<<ans-1<<"\n";
}
return 0;
}
Wavy Tree
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 51 Accepted Submission(s): 20
Problem Description You are given an array b of length n (1≤bi≤109) , consisting of integers. You want to make the array wavy. To do that you can spend some coins, with each coin you can make one element in b increase or decrease by 1. Calculate the minimum number of coins you need to spend to make the array wavy. Input The first line of each test case contains one integer n (1≤n≤106) - the length of array b . The second line contains n integers b1,b2,⋯,bn (1≤bi≤109) - the array b . It’s guarantee that the sum of n among all test cases is not greater than 3×106 . Output Sample Input Sample Output Source 题意: 思路: Painting Game Problem Description Alice and Bob are going to play a game on the strip. They take turns to make move. In one move the player must paint one of the remaining blank grids black, while keeping the rule that no two black grids are adjacent. The game ends when one of the players is unable to paint any grid, and the score of the game is defined as the total number of grids painted black. Alice wants to minimize the score, while Bob wants to maximize it. Given n and the side starting the game, find out the final score when both players play optimally. Input The first line of each test case contains an integer n(1≤n≤109) and a string s(s∈{Alice,Bob}) - the number of grids and the starting player of this game. Output Sample Input Sample Output Source 题意: 思路: Winner Prediction Problem Description At the current state, some matches have ended, and others are yet to start. You are given the results of all ended matches. Write a program to determine whether it is possible for player 1 to win the tournament. You are given T independent test cases. Solve each of them. Input Each of the T test cases consists of multiple lines. The first line contains three integers n,m1,m2(1≤n≤500,1≤m1,m2≤1000), indicating the number of participants, the number of ended matches and the number of upcoming matches. Each of the next m1 lines contains three space-separated integers x,y,z(1≤x,y≤n,x≠y,0≤z≤1), indicating an ended match between player x and player y , z=1 means player x won the match and z=0 means player y won the match. Each of the next m2 lines contains two space-separated integers x,y(1≤x,y≤n,x≠y), indicating an upcoming match between player x and player y. Output Sample Input Sample Output Source 题意: 思路: Average Replacement Problem Description It can be proved that by playing more and more games, each number converges to a certain value. Given the initial numbers written on the hats, your task is to calculate these values. Input For each test case, the first line contains two integers n,m (1≤n,m≤105) . The second line contains n integers a1,a2,⋯,an (1≤ai≤108) , indicating the number on each hat. Each of the following m lines contains two integers u,v (1≤u,v≤n) , indicating a pair of friends. It’s guaranteed that there are no self-loop or multiple edges on the graph, and there are at most 20 test cases such that n>1000 or m>1000. Output Sample Input Sample Output Source 题意: 思路:
An array a of length n is said to be wavy, if for each 1
The first line contains the number of test cases T (1≤T≤103).
For each test case, output one integer, the minimum number of coins you need to spend to make the array wavy.
3
4
1 7 6 5
6
1 2 3 4 5 6
6
1 1 4 5 1 4
2
4
4
2022“杭电杯”中国大学生算法设计超级联赛(10)#include9.Painting Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 57 Accepted Submission(s): 23
There is a paper strip divided into n blank grids. For each i(1≤i
The first line contains an integer T(1≤T≤105) - the number of test cases.
For each test case, output the final score when both players play optimally in a single line.
4
3 Alice
3 Bob
19 Alice
23 Bob
1
2
8
10
2022“杭电杯”中国大学生算法设计超级联赛(10)
在此之前,可以发现,Alice 的一种最优策略是:选某个连续段的左数第二个格子涂黑。
Bob 的一种最优策略是:选某个连续段的左数第三个格子涂黑。#include1.Winner Prediction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 187 Accepted Submission(s): 52
A tournament consisting of n participants is currently taking place. The players are numbered from 1 to n. Every match is between two participants, and there are no draws. The participant who wins the most matches wins the entire tournament; if there are multiple participants tied at the first place, all of them win the tournament.
The first line of input consists of a single integer T(1≤T≤100), indicating the number of test cases. Then T test cases follow.
For each test case, if it is possible of player 1 to win the tournament, print a line YES; otherwise print a line NO.
2
4 2 1
2 3 1
3 2 1
1 4
4 2 2
2 3 1
2 4 1
1 2
3 4
YES
NO
2022“杭电杯”中国大学生算法设计超级联赛(10)#include#include4.Average Replacement
Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 202 Accepted Submission(s): 54
There are n people in a group and m pairs of friends among them. Currently, each person writes an integer on his hat. They plan to play the following game many times: everyone replaces his number on his hat with the average number of his number and all of his friends’ numbers. That is, if before the game the person has a0 written on his hat and a total of k friends, each having number a1,…,ak, then after the game the number on his hat becomes a0+⋯+akk+1. Note that numbers may become non-integers.
The first line contains the number of test cases T (1≤T≤100).
For each test case, output n integers in n lines, indicating the value of each person at last, and the result are reserved with 6 digits after the decimal point.
2
2 1
1 2
1 2
4 2
1 2 3 4
1 2
3 4
1.500000
1.500000
1.500000
1.500000
3.500000
3.500000
2022“杭电杯”中国大学生算法设计超级联赛(10)
因为假设若干轮次之后,某个联通块内还有一个人的数字跟其他数字不一样,那么他就会与他再进行一轮游戏,将数字平均下来。#include