Codeforces Round #698 (Div. 2) 题解 (A-C)

这场的C想了很长时间都没思路,下午补吧。看心情去补D

A. Nezzar and Colorful Balls

题意

给一堆球涂色,球的编号为非递减。相同编号球的颜色必须递增,求颜色个数。

题解

就是数量最多的编号。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define imax 0x3f3f3f3f
#define lmax 0x3f3f3f3f3f3f3f3f 
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        int n,s,last;
        cin>>n;
        int j=0;
        int m=0;
        for(int i=0;i<n;i++){
           cin>>s;
           j++;
           if(i>0) {
               if(last!=s){
                m=max(m,j-1);
                j=1;
               }

           }
           last=s;
        }
        m=max(m,j);
        cout<<m<<endl;
    }

    return 0;

}

B. Nezzar and Lucky Number

题意

幸运数字d是一个1-9的数字,只要十进制表示的数位中含有d,或由已知幸运数字相加而来的数字都是幸运数字,验证一些数字是不是幸运数字。

题解

以7为例,由于70,71,72,73,74,75,76,77,78,79的存在,使得一些比较大的数全都是幸运数字,前面的打表,后面的全都yes即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define imax 0x3f3f3f3f
#define lmax 0x3f3f3f3f3f3f3f3f
bool check(ll num,ll d){
    while(num!=0){
        if(num%10==d) return 1;
        else num=num/10;
    }
    return 0;
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int _;
    cin>>_;
    while(_--){
        bool num[1000];
        memset(num,0,sizeof(num));
        int q,d;
        ll s;
        vector<int> ds;
        cin>>q>>d;
        for(int i=d;i<200;i++){
            if(check(i,d)){
                ds.push_back(i);
                s=i;
                while(s<300){
                    num[s]=1;
                    s+=i;
                }
                for(int j=0;j<ds.size();j++){
                    num[i+ds[j]]=1;
                }
                continue;
            }
            if(num[i]==1){
                for(int j=0;j<ds.size();j++){
                    num[i+ds[j]]=1;
                }
            }
        }
        for(int i=0;i<q;i++){
            cin>>s;
            if(s>190)cout<<"YES"<<endl;
            else if(num[s]==1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }

    }

    return 0;

}

C. Nezzar and Symmetric Array

题意

数组a是一个对称数组(满足a_i=-a_j),d数组由a数组通过d_i=\sum^{2n}_ {j=1} |a_i+a_j|得到,现给出d数组,求是否存在a数组。

题解

这题我一直无法理解,可以参考这个https://blog.csdn.net/Tisfy/article/details/113362438

题目来源于https://codeforces.com/contest/1478

知识共享许可协议
Text is available under CC BY-NC-SA 4.0 unless otherwise stated.

除非特殊声明,本站所有内容均以 CC BY-NC-SA 4.0协议授权。
上一篇
下一篇