Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2)

A题

题意:找到\(S(x)>S(x+1)\)的数在\(x∈(0,n)\)的范围内的个数S(x)是x的个数数字的和。容易发现x的末尾数字是9时S(x)>S(x+1) 才成立。所以答案是x/10+(x%10==9)

#include <bits/stdc++.h>
#define re register
#define pb push_back
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long ;
const int N = 1e5+10 ;
int fan(int n){
    int res=0;
    while(n){
        res+=n%10;
        n/=10;
    }
    return res;
}
vector<int>ans;
int check(int n){
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(fan(i)>fan(i+1))cnt++;
    return cnt;
}
void solve()
{
    int n;cin>>n;
    int cnt=0;
    if(n%10==9) cnt=1;
    cout<<n/10+cnt<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

B题

题意:先往右任意次,再往左任意次(往左之后不能往右了,往右可能0次)可不可能由a串组成b串。模拟就行

#include <bits/stdc++.h>
#define re register
#define pb push_back
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long ;
const int N = 1e4+10 ;
char a[N],b[N];
int n,m;
bool flag=0;
void dfs(int u,int v,int cnt){
    if(flag)return ;
    if(u+1<=n){
        if(a[u+1]==b[v+1]){
            dfs(u+1,v+1,cnt+1);
        }
    }
    int x=u,y=v;
        while(true){
            if(x-1>=1&&a[x-1]==b[y+1])x--,y++;
            else break;
        }
    if(y==m)flag=1;
}
void solve()
{
    flag=0;
    cin>>(a+1)>>(b+1);
    n=strlen(a+1);
    m=strlen(b+1);
    for(int i=1;i<=n;i++)
    if(a[i]==b[1]){
        dfs(i,1,0);
        if(flag){
            cout<<"YES\n";
            return ;
        }
    }
    cout<<"NO\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

C题

题意:两只队伍踢球什么时候能最快结束。直接模拟队伍的可能性就行。

#include <bits/stdc++.h>
#define re register
#define pb push_back
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long ;
char s[110];
void solve()
{
    cin>>s;
    int ans=10;
    for(int t=0;t<1<<12;t++){
        bool f=1;
        int a=0,b=0,res=10;
        for(int i=0;i<10;i++){
            int u=t>>i&1;
            if(s[i]!='?'&&(s[i]-'0')!=u){
                f=0;
                break;
            }
            if(u){
                if(i%2==0)a++;
                else b++;
            }
            if(a>b){
                if(abs(a-b)>(10-i)/2) res=min(res,i+1);
            }
            else{
                if(abs(a-b)>(10-i-1)/2) res=min(res,i+1);
            }
        }
        if(f)ans=min(ans,res);
        if(0){
            for(int i=0;i<10;i++)
                cout<<(t>>i&1)<<" ";
            cout<<endl;
        }
    }
    cout<<ans<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}
上一篇:GridViewColumn.CellTemplate


下一篇:Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) A~D题解