zl程序教程

您现在的位置是:首页 >  其它

当前栏目

Acwing第 56 场周赛【完结】

AcWing 56 周赛 完结
2023-09-11 14:15:52 时间

https://www.acwing.com/activity/content/competition/problem_list/1939/

4482. 分组

在这里插入图片描述

#include<bits/stdc++.h> 
using namespace std;
const int N=1e4+10;
int n,a[N],ans;
map<int,int>mp;
int main(void)
{
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i],mp[a[i]]++,ans=max(ans,mp[a[i]]);
	cout<<ans;
	return 0;
}
#include<bits/stdc++.h> 
using namespace std;
const int N=1e4+10;
int n,a[N];
int main(void)
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    vector< map<int,int> >ve;
    for(int i=0;i<n;i++)
    {
        if(ve.size()==0)
        {
            map<int,int>mp; mp[a[i]]++;
            ve.push_back(mp);
        }else
        {
            bool flag=1;
            for(int j=0;j<ve.size();j++)
            {
                auto temp=ve[j];
                if(temp.count(a[i])==0) 
                {
                    temp[a[i]]++;
                    ve[j]=temp;
                    flag=0;
                    break;
                }
            }
            if(flag) 
            {
                map<int,int>mp; mp[a[i]]++;
                ve.push_back(mp);
            }
        }
    }
    cout<<ve.size()<<endl;
    return 0;
}

4483. 格斗场

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,k,a[N],st[N];
priority_queue<int,vector<int>,greater<int>>q;
int main(void)
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),st[a[i]]++;
	int ans=0;
	for(int i=1;i<=1e6;i++) if(st[i]) q.push(i);
	while(q.size()>=2) 
	{
		auto s1=q.top(); q.pop();
		auto s2=q.top(); q.pop();
		if(abs(s1-s2)<=k) 
		{
			st[s1]--;
			if(st[s1]) q.push(s1);
			q.push(s2); 
		}else q.push(s2);
	}
	for(int i=1;i<=1e6;i++) if(st[i]) ans+=st[i];
	cout<<ans;
	return 0;
}

4484. 有限小数【思维】

在这里插入图片描述
q整除b^k

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL gcd(LL a,LL b)
{
    return b?gcd(b,a%b):a;
}
int main(void)
{
	int t; scanf("%d",&t);
	while(t--)
	{
		LL p,q,b; scanf("%lld%lld%lld",&p,&q,&b);
		LL d=gcd(p,q);
		q/=d;
		while(q>1)
		{
			d=gcd(q,b);
			if(d==1) break;
			while(q%d==0) q/=d;
		}
		if(q==1) puts("YES");
		else puts("NO");
	}
	return 0;
}