Codeforces Round #698 (Div. 2) 补题

A题

直接猜的。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=110;
int a[N];
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int res=1;
    int ans=0;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==a[i-1])
        {
            res++;
        }
        else 
        {
            ans=max(ans,res);
            res=1;
        }
    }
    ans=max(ans,res);
    cout<<ans<<endl;
}


int main()
{
    int t;
    t=1;
    cin>>t;

    while(t--)
    {
        solve();
    }
}

B题

  • 思路
    如果a[i]>10*d的话,直接yes,因为例如7,70-79都对,80以后的数字都可以用71-79加上一个7的倍数表示。
    小于直接打表。
  • 代码
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e4 + 10;

ll a[N];

bool get_s(ll x, ll d)
{
    bool flag = true;
    string s = to_string(x);
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] - '0' == d)
        {
            flag = false;
            break;
        }
    }
    if (!flag)
        return true;
    else
        return false;
}

void solve()
{
    ll q, d;
    cin >> q >> d;
    for (int i = 1; i <= q; i++)
        cin >> a[i];
    ll dp[11] = {-1};
    for (int i = 1; i <= 9; i++)
        dp[i] = (d * i) % 10;
    for (int i = 1; i <= q; i++)
    {
        if (get_s(a[i], d))
        {
            cout << "Yes" << endl;
        }
        else
        {
            ll x = a[i] % 10;
            bool flag = false;
            if (a[i] % d == 0)
            {
                cout << "Yes" << endl;
                continue;
            }
            if (a[i] >= d * 10)
            {
                flag = true;
                cout << "Yes" << endl;
                continue;
            }
            for (int j = 1; j <= 9; j++)
            {
                if (x == dp[j])
                {
                    if (a[i] >= j * d)
                    {
                        flag = true;
                        cout << "Yes" << endl;
                        break;
                    }
                    else
                        continue;
                }
            }
            if (!flag)
            {
                cout << "No" << endl;
            }
        }
    }
}

int main()
{
    int t;
    t = 1;
    cin >> t;

    while (t--)
    {
        solve();
    }
}

C题

在这里插入图片描述

注:

某个大佬的,侵权删除。

D题

  • 题意
    在这里插入图片描述

  • 思路
    因为2*x-y=x+x-y,相当于加上和任意数的差,所以只需要判断一下数组中的任意一个是否能够加上多少称为k。加上多少的这个数就是所有数差的gcd。

  • 代码

#include<bits/stdc++.h>

using namespace std;

#define ll long long 
ll a[202020];

int main()
{
    ll k,n,t,T=1;
    cin>>T;
    while(T--)
    {
        cin>>n>>k;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        ll g=abs(a[1]-a[2]);
        for(int i=3;i<=n;i++)
            g=__gcd(g,abs(a[i]-a[i-1]));
        if((k-a[1])%g==0)
            cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
}
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

疯狂的码泰君

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

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

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

打赏作者

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

抵扣说明:

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

余额充值