2022/6/18 周赛

A:4482. 分组

关键词:贪心

题意:将一个数组分成尽可能少的数组,并且每个数组内数字不重复

思路:贪心,即求出现最多数的出现次数

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int n;
int cnt[N];

int main()
{
    cin >> n;

    int x;
    int res =0;
    
    for (int i = 0; i < n; i ++)
    {
        cin >> x;
        cnt[x] ++;
        res = max(res , cnt[x]);
    }
        
    cout << res <<endl;
    return 0;
}

B:4483. 格斗场

关键词:贪心、双指针、二分

题意:若两人权值相差<=k 且不相等,则可以删除权值小的那个人,给定一批人的权值,求最后最少能剩几人

思路:贪心,排序后从小到大进行淘汰,利用双指针进行维护一个a[j]使得a[j]为最小的 x ,x 刚好满足x - a[i] > k

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 200010;

int n,k;
int a[N];


int main( )
{
    cin >> n >> k;
    for (int i = 0; i < n; i ++)
        cin >> a[i];
    
    sort(a, a + n);
    
    int res = n;
    for (int i = 0, j = 0; i < n; i ++)
    {
        while (j < n && a[j] - a[i] <= k) j ++;   
        if (a[j - 1] != a[i]) res --;
        
    }
    
    cout << res <<endl;
    return 0;
}

C:4484. 有限小数

关键词:数论

题意:给定三个整数 p,q,b,请你计算十进制表示下的 p/q 的结果在 b 进制下是否为有限小数。

思路:整数部分小数部分进制间转换

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b)
{
    return b ? gcd(b, a % b) : a;
}

int main()
{
    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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值