AtCoder Beginner Contest 296 ABCD

发布时间 2023-04-01 23:38:00作者: 高尔赛凡尔娟

https://atcoder.jp/contests/abc296

A - Alternately

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        bool flag=true;
        LL n;
        cin>>n;
        string s;
        cin>>s;
        for(int i=0;i<n;i++)
        {
            if(s[i]==s[i-1])
            {
                flag=false;
                break;
            }
        }
        if(flag==false) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

B - Chessboard

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
map<LL,char> c;
map<LL,LL> r;
char a[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        c[1]='a',c[2]='b',c[3]='c';
        c[4]='d',c[5]='e',c[6]='f';
        c[7]='g',c[8]='h';
        for(int i=8;i>=1;i--)
        {
            r[i]=(8-i+1);
        }
        for(int i=1;i<=8;i++)
        {
            for(int j=1;j<=8;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='*') cout<<c[j]<<r[i]<<endl;
            }
        }
    }
    return 0;
}

C - Gap Existence

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
LL a[N],x;
map<LL,LL> mp;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n,x;
        cin>>n>>x;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        bool flag=false;
        for(int i=1;i<=n;i++)
        {
            if(mp[x+a[i]]!=0)
            {
                flag=true;
                break;
            }
        }
        if(flag==false) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

D - M<=ab

题目大意:

给定一个n和m,要求我们找出a*b>=m中最小的a*b,a和b都必须在1-n的范围内.

这题m的数据范围在1e12之内,说明x*y在le12之内,即x和y最大在1e6处。

因此可以用O(n)的时间复杂度暴力解决。
Sample Input 3  
100000 10000000000
Sample Output 3  
10000000000
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;
const LL N=2e6+10,M=3023;
const LL mod=100000007;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n,m;
        cin>>n>>m;
        LL flag=1e6;
        LL ans=MAXN;
        for(int i=1;i<=min(flag,n);i++)
        {
            LL x=(m+i-1)/i;//m的基础上加上i-1,避免取整时降低次数
            if(x<=n) ans=min(x*i,ans);//这一部分也在范围内,才可以进行比较
        }
        if(ans==MAXN) cout<<"-1"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}