题目链接

A.Race

题意:


题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int v1,v2,t,s,l;
    cin>>v1>>v2>>t>>s>>l;
    int sec=1,a=0,b=0,f=0;
    while(1){
        if(a-b>=t&&!f)f=s;
        if(!f)a+=v1;
        else f--;
        b+=v2;
        if(a==l||b==l)break;
        sec++;
    }
    if(a==l&&b==l)cout<<"Tie "<<sec;
    else if(a==l)cout<<"Ming "<<sec;
    else cout<<"Hong "<<sec;
    return 0;
}


B.Min Value

题意:


题解:



AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

struct node{
    int x,id;
    bool operator <(const node &t)const{
        return x<t.x;
    }
}a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].x,a[i].id=i;
    sort(a+1,a+1+n);
    int ans1=inf,ans2;
    for(int i=1;i<=n;i++){
        int p=lower_bound(a+1,a+1+n,(node){-a[i].x,a[i].id})-a;
        p=max(1,p);
        if(p>1&&p-1!=i)
            if(abs(a[i].x+a[p-1].x)<ans1)ans1=abs(a[i].x+a[p-1].x),ans2=a[i].id+a[p-1].id;
            else if(abs(a[i].x+a[p-1].x)==ans1)ans2=min(ans2,a[i].id+a[p-1].id);
        if(p!=i)
            if(abs(a[i].x+a[p].x)<ans1)ans1=abs(a[i].x+a[p].x),ans2=a[i].id+a[p].id;
            else if(abs(a[i].x+a[p].x)==ans1)ans2=min(ans2,a[i].id+a[p].id);
        if(p+1<=n&&p+1!=i)
            if(abs(a[i].x+a[p+1].x)<ans1)ans1=abs(a[i].x+a[p+1].x),ans2=a[i].id+a[p+1].id;
            else if(abs(a[i].x+a[p+1].x)==ans1)ans2=min(ans2,a[i].id+a[p+1].id);
    }
    cout<<ans1<<' '<<ans2;
    return 0;
}


C. Coronavirus

题意:



题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

char g[100][100];
bool vis[100][100];
struct node{
    int x,y,s;
};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int sx,sy;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            cin>>g[i][j];
            if(g[i][j]=='S')sx=i,sy=j;
        }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(g[i][j]=='*'){
                vis[i][j]=1;
                for(int k=0;k<8;k++){
                    int dx=i+dir[k][0];
                    int dy=j+dir[k][1];
                    if(dx<1||dx>n||dy<1||dy>m)continue;
                    if(g[dx][dy]=='E'){cout<<"Impossible";return 0;}
                    vis[dx][dy]=1;
                }
            }
    queue<node> q;
    q.push((node){sx,sy,0});vis[sx][sy]=1;
    while(!q.empty()){
        node p=q.front();
        q.pop();
        if(g[p.x][p.y]=='E'){cout<<p.s;return 0;}
        for(int i=0;i<4;i++){
            int dx=p.x+dir[i][0];
            int dy=p.y+dir[i][1];
            if(dx<1||dx>n||dy<1||dy>m||vis[dx][dy])continue;
            vis[dx][dy]=1;
            q.push((node){dx,dy,p.s+1});
        }
    }
    cout<<"Impossible";
    return 0;
}


D. Array

题意:


题解:

本场题解连接

AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll u,v;
    while(cin>>u>>v){
        if(v-u<0||(v-u)%2){cout<<-1<<endl;continue;}
        ll d=v-u;
        if(!d){
            if(!u)cout<<0;
            else cout<<1;
        }
        else{
            ll t=d/2;
            if((t&u)==0)cout<<2;
            else cout<<3;
        }
        cout<<endl;
    }
    return 0;
}


G.XOR

题意:


题解:




AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;
    cin>>n;
    if(n==1){cout<<0;return 0;}
    ll ans=0,cnt=0;
    while(n)ans+=(1ll<<cnt),cnt++,n>>=1;
    cout<<ans;
    return 0;
}


H.Maze

题意:



题解:






AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n,m;
char g[3010][3010];
int fa[10000010],sz[10000010];
int find(int x){
    if(fa[x]==x)return x;
    return fa[x]=find(fa[x]);
}
int id(int i,int j){
    return (i-1)*m+j;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int q;
    cin>>n>>m>>q;
    for(int i=1;i<=n*m;i++)fa[i]=i;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>g[i][j];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            for(int k=0;k<4;k++){
                int dx=i+dir[k][0];
                int dy=j+dir[k][1];
                if(dx<1||dx>n||dy<1||dy>m||g[dx][dy]==g[i][j])continue;
                fa[find(id(i,j))]=find(id(dx,dy));
            }

    for(int i=1;i<=n*m;i++)sz[find(i)]++;
    for(int i=1;i<=n*m;i++)sz[i]=sz[find(i)];
    while(q--){
        int x,y;
        cin>>x>>y;
        cout<<sz[id(x,y)]<<endl;
    }
    return 0;
}


I.Prime

题意:

题解:





AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

int prime[maxn];
bool isprime[10000010];
int num=0;
void Prime(int n){
    memset(isprime,true,sizeof(isprime));
    for(int i=2;i<=n;i++){
        if(isprime[i]) prime[++num]=i;
        for(int j=1;j<=num;j++){
            if(i*prime[j]>n) break;
            isprime[i*prime[j]]=false;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    Prime(10000000);
    int _;
    cin>>_;
    while(_--){
        int l,r;
        cin>>l>>r;
        int p=lower_bound(prime+1,prime+1+num,l)-prime-1;
        int q=upper_bound(prime+1,prime+1+num,r)-prime-1;
        cout<<q-p<<endl;
    }
    return 0;
}

J.Compare

题意:



题解:



AC代码

a=int(input())
b=int(input())
if a>b :
    print('>')
elif a==b:
    print('=')
else :
    print('<')

K.Walk

题意:

题解:










AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
ll fact[maxn],inv1[maxn];
ll Pow(ll a, ll b){
    ll ans = 1;
    while(b > 0){
        if(b & 1){
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
//逆元
ll inv(ll b){
    return Pow(b,mod-2)%mod;
}



ll C(ll n,ll m){
    if(m>n||n<0||m<0)return 0;
    if(m==0||m==n) return 1;
    ll res=(fact[n]*inv1[m]%mod*inv1[n-m])%mod;
    return res;
}

void init() {
    fact[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = fact[i - 1] * i %mod;
    }
    inv1[maxn - 1] = Pow(fact[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 0; i--) {
        inv1[i] = inv1[i + 1] * (i + 1) %mod;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    init();
    int _;
    cin>>_;
    while(_--){
        int n,m;
        cin>>n>>m;
        cout<<C(n+m-2,n-1)<<endl;
    }
    return 0;
}

L. Defeat the monster

题意:



题解:






AC代码

/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=5;j++){
            int p=lower_bound(a+1,a+1+n,a[i]-j)-a-1;
            int q=upper_bound(a+1,a+1+n,a[i]+5-j)-a-1;
            p=max(0,p);q=min(n,q);
            ans=max(ans,q-p);
        }
    }
    cout<<ans;
    return 0;
}