当前位置:网站首页>Acwing's 57th weekly match -- BC question is very good

Acwing's 57th weekly match -- BC question is very good

2022-06-27 05:03:00 Wawa source

A. Than the size — Sign in

#include<iostream>
#include<cstring>
using namespace std;
#define int long long
signed main()
{
    
	int n;cin>>n;
	int s1=0,s2=0;
	for(int i=0,x;i<n;i++)cin>>x,s1+=x;
	for(int i=0,x;i<n;i++)cin>>x,s2+=x;
	if(s1>=s2)cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
}

B. Digital operation — Basic theorem of arithmetic

#include<iostream>
#include<cstring>
#include<set>
#include<cmath>
using namespace std;
#define int long long
set<int>S;
signed main()
{
    

	int n;cin>>n;
	if(n==1){
    cout<<1<<" 0"<<'\n';return 0;}
	int res=1,cnt=0;
	for(int i=2;i<=n;i++)
	{
    
	    int s=0;
	    if(n%i==0)
	    {
    
	        while(n%i==0)n/=i,s++;
	        res*=i;
	        S.insert(s);
	    }
	    cnt=max(s,cnt);
	}
	int sum=1,res2=1;
	while(sum<cnt)sum*=2,res2++;
	if(sum==cnt&&S.size()==1)res2--;
	cout<<res<<" "<<res2<<'\n';
	
	
}

C. The longest continuous subsequence — Monotonic stack + greedy + Two points

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N = 1000010; 
int a[N],s[N],stk[N];
int top=0;
signed main()
{
    
	int n;cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],a[i]-=100;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];
	int res=0;
	for(int i=1;i<=n;i++)
	{
    
	    
	    int l=0,r=top;
	    while(l<r)
	    {
    
	        int mid=l+r>>1;
	        if(s[i]-s[stk[mid]]>0)r=mid;
	        else l=mid+1;
	    }
	    if(s[i]<s[stk[top]])stk[++top]=i;
	    if(s[i]-s[stk[r]]>0)res=max(res,i-stk[r]);
	}
	cout<<res<<'\n';
}
原网站

版权声明
本文为[Wawa source]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270438226727.html