当前位置:网站首页>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;
}
边栏推荐
- 低度酒赛道进入洗牌期,新品牌如何破局三大难题?
- Unpool(nn.MaxUnpool2d)
- Blue bridge - maximum common divisor and minimum common multiple
- Timescaledb 2.5.2 release, time series database based on PostgreSQL
- Pytorch register_ Hook (operate on gradient grad)
- Character painting, I use characters to draw a Bing Dwen Dwen
- [source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
- [機緣參悟-38]:鬼穀子-第五飛箝篇 - 警示之一:有一種殺稱為“捧殺”
- Naacl 2021 | contrastive learning sweeping text clustering task
- Design and implementation of campus epidemic prevention and control system based on SSM
猜你喜欢
. Net starts again happy 20th birthday
Openresty ngx Lua Execution stage
【LeetCode】106. Construct binary tree from middle order and post order traversal sequence (wrong question 2)
Pytest (4) - test case execution sequence
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
Exploration of short text analysis in the field of medical and health (I)
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
Grub 2.12 will be released this year to continue to improve boot security
Action News
openresty ngx_lua执行阶段
随机推荐
JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
8. Commodity management - commodity classification
如何做一个炫酷的墨水屏电子钟?
CAM Pytorch
The phenomenology of crypto world: Pioneer entropy
Leetcode takes out the least number of magic beans
A label colorful navigation bar
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
[illumination du destin - 38]: Ghost Valley - chapitre 5 Flying clamp - one of the Warnings: There is a kind of killing called "hold Kill"
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 1)
Some query constructors in laravel (2)
Pgadmin 4 V6.5 release, PostgreSQL open source graphical management tool
使用druid連接MySQL數據庫報類型錯誤
A tab Sina navigation bar
【LeetCode】404. Sum of left leaves (2 brushes of wrong questions)
Limited query of common SQL operations
【LeetCode】222. The number of nodes of a complete binary tree (2 mistakes)
Structure of ViewModel
Elk log analysis system
Abacus mental arithmetic test