当前位置:网站首页>Acwing第 58 场周赛【完结】
Acwing第 58 场周赛【完结】
2022-07-05 02:37:00 【辉小歌】
没打,赛后vp了一下题目好简单。
15min做完
https://www.acwing.com/activity/content/competition/problem_list/1994/、
4488. 寻找1【签到】
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int n,x,flag=0;
cin>>n;
while(n--)
{
cin>>x;
if(x) flag=1;
}
if(flag) puts("YES");
else puts("NO");
return 0;
}
4489. 最长子序列【贪心 / 双指针】

#include<bits/stdc++.h>
using namespace std;
const int N=1e5*3+10;
int n,a[N];
int main(void)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int cnt=1,last=1,ans=1;
for(int i=2;i<=n;i++)
{
if(a[i]<=a[last]*2) cnt++,last=i;
else last=i,cnt=1;
ans=max(ans,cnt);
}
cout<<ans;
return 0;
}
4490. 染色【思维】

画图,你会发现只要其颜色和父亲颜色不一样就加1.
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*3+10;
int h[N],e[N],ne[N],idx;
int w[N],n,cnt=1;
void add(int a,int b)
{
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u,int fa)
{
if(fa!=-1&&w[u]!=w[fa]) cnt++;
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
if(j==fa) continue;
dfs(j,u);
}
}
int main(void)
{
memset(h,-1,sizeof h);
cin>>n;
for(int i=2;i<=n;i++)
{
int x; cin>>x;
add(x,i),add(i,x);
}
for(int i=1;i<=n;i++) cin>>w[i];
dfs(1,-1);
cout<<cnt;
return 0;
}
边栏推荐
- Advanced learning of MySQL -- Application -- Introduction
- openresty ngx_lua执行阶段
- Pytest (4) - test case execution sequence
- 丸子百度小程序详细配置教程,审核通过。
- GFS分布式文件系统
- Exploration of short text analysis in the field of medical and health (II)
- Design and practice of kubernetes cluster and application monitoring scheme
- STL container
- GFS distributed file system
- 【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
猜你喜欢

【LeetCode】111. Minimum depth of binary tree (2 brushes of wrong questions)

Pytest (5) - assertion

Visual studio 2019 set transparent background (fool teaching)

ELK日志分析系统

ELFK部署

Naacl 2021 | contrastive learning sweeping text clustering task

Asynchronous and promise

Can you really learn 3DMAX modeling by self-study?

Zabbix

. Net starts again happy 20th birthday
随机推荐
Luo Gu Pardon prisoners of war
丸子百度小程序详细配置教程,审核通过。
Zabbix
He was laid off.. 39 year old Ali P9, saved 150million
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Official announcement! The third cloud native programming challenge is officially launched!
Design of KTV intelligent dimming system based on MCU
Word processing software
Open source SPL optimized report application coping endlessly
Advanced conditional statements of common SQL operations
172. Zero after factorial
Prometheus monitors the correct posture of redis cluster
Summary and practice of knowledge map construction technology
Practice of tdengine in TCL air conditioning energy management platform
Using druid to connect to MySQL database reports the wrong type
LeetCode --- 1071. Great common divisor of strings problem solving Report
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
【LeetCode】98. Verify the binary search tree (2 brushes of wrong questions)
openresty ngx_lua变量操作