当前位置:网站首页>Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
2022-07-03 11:52:00 【qq_ fifty-one million thirty-four thousand one hundred and forty】
A topic Will Missing
source : Adapted from rescue
Investigate : Joseph's mastery of the problem
difficulty : Orange question
This problem is the classic Joseph problem , The difference is that the number is fixed as 2, And only need to output the number of the last person , If you don't understand, search Joseph's question .
B topic Christmas lights
source : Adapted from expression bracket matching
Investigate : The basic use of stack
difficulty : Orange question
This topic uses a stack Remove bracket , If the current bracket is { , Put in stack, Otherwise check stack Is there a { Or empty .
C topic Under Hawkins
source : Based on the [JLOI2009] Binary tree problem
Investigate : Basic application of binary tree
difficulty : Orange question
This question can be used dfs Realize the solution of depth , And in dfs Record the number of nodes in each layer , Finally, find the largest is the width .
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,fa[1005],de[1005],tot,head[1005],s,kuan,shen,pika[1005];
struct node
{
int to,next;
}edge[1005];
void add(int u,int v)
{
edge[++tot].to=v;
edge[tot].next=head[u];
head[u]=tot;
}
void dfs(int x,int fath)
{
fa[x]=fath;
de[x]=de[fath]+1;
for(int i=head[x];i;i=edge[i].next)
{
if(edge[i].to!=fath)
{
dfs(edge[i].to,x);
}
}
}
int main()
{
cin>>n;
for(int i=1;i<n;i++)
{
int x,y;
cin>>x>>y;
add(x,y);
add(y,x);
}
dfs(1,0);
for(int i=1;i<=n;i++)
{
shen=max(de[i],shen);
pika[de[i]]++;
}
for(int i=1;i<=shen;i++)
{
kuan=max(kuan,pika[i]);
}
cout<<shen<<" "<<kuan<<endl;
return 0;
}D topic Best nanny
source : Niuke Xiaobai moon race 6 H topic - ditch
Investigate : graph theory , Minimum spanning tree
difficulty : Yellow title
This topic is called minimum spanning tree Kruskal Board question , Those who don't understand can search .
#include<bits/stdc++.h>
using namespace std;
struct edge
{
int s,t,d;
bool operator<(const edge& y)const
{
return d<y.d;
}
}e[500005];
int n,m,i,f[100005],ans;
int get(int x)
{
if(f[x]==x)return x;
return f[x]=get(f[x]);
}
int main()
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)f[i]=i;
for(i=1;i<=m;i++)scanf("%d%d%d",&e[i].s,&e[i].t,&e[i].d);
sort(e+1,e+m+1);
for(i=1;i<=m;i++)if(get(e[i].s)!=get(e[i].t))
{
ans+=e[i].d;
f[get(e[i].s)]=get(e[i].t);
}
cout<<ans<<endl;
return 0;
}E topic Winter dance
source : Weekend dance
Investigate : The basic use of queues
difficulty : Orange question
This topic is to use queue Save the number , If the current person finishes dancing, just get out of the queue and rejoin the queue , And so on .
F topic Battle of Star City (Easy Version)
source : Adapted from Niuke practice race 101 B topic - God of famine is here
Investigate :dp( State machine )
difficulty : Yellow title
For everyone , His sum parity is related to the next one , If the previous contribution is even , Then our current contribution must be even , Otherwise, it will be odd . If current bit i For even numbers 0-i There is just i - i / 2 + 1 An even number makes the current bit contribution an even number ,i / 2 Odd numbers make the current bit contribution odd , Because even numbers + Odd number = Odd number . about i In an odd number of , It is not difficult to find that even and odd numbers are (i + 1) / 2. Calculate the odd and even numbers and then directly dp Just transfer .
#include<bits/stdc++.h>
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 998244353;
using namespace std;
ll dp[20202000][3];// The second dimension is 0 For even numbers ,1 It's odd
int main() {
int n;
cin >> n;
dp[1][0] = 1, dp[1][1] = 1;
for (ll i = 2; i <= n; i++) {
ll x, y; //x Contribute an odd number to the current bit ,y For the even
if (i % 2 == 0) {
x = i / 2, y = i + 1 - i / 2;
}
else {
x = (i + 1) / 2, y = (i + 1) / 2;
}
dp[i][1] = dp[i - 1][0] * x % mod;
dp[i][1] = (dp[i][1] + dp[i - 1][1] * y) % mod;
dp[i][0] = dp[i - 1][1] * x % mod;
dp[i][0] = (dp[i][0] + dp[i - 1][0] * y) % mod;
}
cout << dp[n][0] % mod;
return 0;
}G topic Battle of Star City (Hard Version)
source : Adapted from Niuke practice race 101 B topic - God of famine is here
Investigate :dp( State machine ), number theory ( Divide and divide )
difficulty : Green topic
dp The equation of follows F Consistent questions , The only difference is how to find odd and even numbers , Due to the large range of data , If violence solves each i The odd and even numbers owned , Then the time complexity is as high as
, The data range is 1e5, The limit case is 1e10, Obviously it's going to be overtime . Therefore, this topic needs to use the idea of dividing into blocks , The time complexity can be optimized to
, The limit case is 3e7 about , No timeout . For the practice of dividing and dividing blocks, please refer to 【 number theory 】 Divide and divide ( Number theory is divided into blocks )_ Ci tree c The blog of -CSDN Blog _ Divide into blocks .
FG You can also enumerate some numbers by yourself , And find the rules , It's not hard to find out .
边栏推荐
- uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
- R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
- R语言使用aggregate函数计算dataframe数据分组聚合的均值(sum)、不设置na.rm计算的结果、如果分组中包含缺失值NA则计算结果也为NA
- (数据库提权——Redis)Redis未授权访问漏洞总结
- Keepalived中Master和Backup角色选举策略
- Go语言实现静态服务器
- OpenGL 着色器使用
- 利用Zabbix动态监控磁盘I/O
- vulnhub之Ripper
- Sheet1$. Output [excel source output] Error in column [xxx]. The returned column status is: "the text is truncated, or one or more characters have no matches in the target code page.".
猜你喜欢

Machine learning 3.2 decision tree model learning notes (to be supplemented)

Viewing binary bin files with notepad++ editor

Numpy np.max和np.maximum实现relu函数

Ripper of vulnhub

《剑指offer 03》数组中重复的数字

机器学习 3.2 决策树模型 学习笔记(待补)

导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....

OpenGL 索引缓存对象EBO和线宽模式

同事写了一个责任链模式,bug无数...

vulnhub之Nagini
随机推荐
CGroup introduction
剑指offer专项32-96题做题笔记
vulnhub之presidential
Raven2 of vulnhub
836. Merge sets (day 63) and search sets
Dynamic programming (interval DP)
量化计算调研
"Jianzhi offer 04" two-dimensional array search
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
Xml的(DTD,xml解析,xml建模)
MySQL union和union all区别
Slam mapping and autonomous navigation simulation based on turnlebot3
vulnhub之GeminiInc v2
Qt+VTK+OCCT读取IGES/STEP模型
MySQL searches and sorts out common methods according to time
Cacti monitors redis implementation process
鸿蒙第四次培训
Vulnhub narak
vulnhub之tomato(西红柿)
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.