当前位置:网站首页>Acwing game 58 [End]

Acwing game 58 [End]

2022-07-05 02:38:00 Hui Xiaoge

Didn't fight , After the game vp The topic is so simple .
15min finish
https://www.acwing.com/activity/content/competition/problem_list/1994/、

4488. seek 1【 Sign in 】

#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. The longest subsequence 【 greedy / Double pointer 】

 Insert picture description here

#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. dyeing 【 thinking 】

 Insert picture description here
drawing , You will find that as long as the color is different from that of your father, you can add it 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;
}
原网站

版权声明
本文为[Hui Xiaoge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050235433293.html