AcWing 第 56 场周赛

目录

4482. 分组

4483. 格斗场

4484. 有限小数


4482. 分组

4482. 分组

思路

找到每个数的最大次数,该数据中的最大次数就是最大分组数

代码如下

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 2e5 + 10, mod = 1e9 + 7;

int n;
int st[N];

int main()
{
    //fast;
    //cin >> T;
    scanf("%d", &n);
    
    int x = 0, mx = 0;
    for(int i = 0; i < n; i ++ )
        scanf("%d", &x), st[x] ++, mx = max(mx, st[x]);
    
    printf("%d\n", mx);

    return 0;
}

4483. 格斗场

4483. 格斗场

思路:设置原数组的元素数组和该元素的数量数组,降序排列元素组,离散化为原数组。

明确几点:

1)存在比本数大的数且符合题目规则,则本数的数量清零。

2)想要存最小的数量,即将所有可以删去的元素都删去。即、将每个数的可以删去的数都删去,即判断该数之后的 K 范围的数,可以简化为判断每相邻的两个数是否可以删去。

代码如下

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e6 + 10, mod = 1e9 + 7;

int n, k;
int st[N];
int b[N];

int main()
{
    //fast;
    //cin >> T;
    scanf("%d %d", &n, &k);
    
    vector<int> a(n);
    
    int x = 0, res = 0;
    for(int i = 0; i < n; i ++ )
        scanf("%d", &a[i]), st[a[i]] ++;
    
    sort(a.begin(), a.end(), greater<int>());
    a.erase(unique(a.begin(), a.end()), a.end());
    
    res += st[a[0]];
    int t = a[0];
    for(int i = 1; i < a.size(); i ++ )
    {
        if(a[i-1] - a[i] <= k) st[a[i]] = 0;
    }
    
    int cnt = 0;
    for(int i = 0; i < a.size(); i ++ )
    {
        if(st[a[i]]) b[cnt++] = a[i];
    }
    
    for(int i = 1; i < cnt; i ++ )
    {
        if(t - b[i] > k)
        {
            t = b[i], res += st[b[i]];
        }
    }
    
    
    printf("%d\n", res);

    return 0;
}

4484. 有限小数

4484. 有限小数 

思路:判断有限小数,即判断小数部分的b次方是否可以被,即判断 p/q*b^n是否为整数,即判断b^n/q是否为整数,将q中的与b的公因数除净,然后判断q是否为1 , 为1 代表可以整除,反之无法整除

代码如下

#include <bits/stdc++.h>

#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e6 + 10, mod = 1e9 + 7;

int n;
LL p, q, b;

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

int main()
{
    //fast;
    //cin >> T;
    scanf("%d", &n);
    while(n -- )
    {
        scanf("%lld %lld %lld", &p, &q, &b);
        
        LL d = gcd(p, q);
        q /= d;
        
        while(q > 1)
        {
            LL t = gcd(q, b);
            if(t == 1) break;
            while(q % t == 0) q /= t;
        }
        
        if(q == 1) puts("YES");
        else puts("NO");
    }
    
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AC自动寄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值