当前位置:网站首页>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;
}
边栏推荐
- Action News
- STL container
- The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
- Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
- TCP security of network security foundation
- Visual explanation of Newton iteration method
- Moco V2 literature research [self supervised learning]
- Go RPC call
- openresty ngx_lua執行階段
- 数据库和充值都没有了
猜你喜欢
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
Exploration of short text analysis in the field of medical and health (II)
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
A label making navigation bar
Hmi-31- [motion mode] solve the problem of picture display of music module
A label colorful navigation bar
Chinese natural language processing, medical, legal and other public data sets, sorting and sharing
[技术发展-26]:新型信息与通信网络的数据安全
官宣!第三届云原生编程挑战赛正式启动!
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
随机推荐
ICSI 311 Parser
Chinese natural language processing, medical, legal and other public data sets, sorting and sharing
The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
Cut! 39 year old Ali P9, saved 150million
Go RPC call
Traditional chips and AI chips
Blue bridge - maximum common divisor and minimum common multiple
[机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
【微服务|SCG】Filters的33种用法
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
Video display and hiding of imitation tudou.com
[technology development-26]: data security of new information and communication networks
Exploration of short text analysis in the field of medical and health (I)
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
179. Maximum number - sort
Kotlin - 协程 Coroutine
Grub 2.12 will be released this year to continue to improve boot security
JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
Kotlin - coroutine
Marubeni Baidu applet detailed configuration tutorial, approved.