文章

The 15th UESTC Fun Programming Contest Round 3

The 15th UESTC Fun Programming Contest Round 3

A. Numeronym

对长度大于3的单词缩写

Code

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;

    if (s.length() > 3) {
        cout << s[0] << (s.length() - 2) << s[s.length() - 1] << endl;
    } else {
        cout << s << endl;
    }

    return 0;
}

B. Sleeping? Training?

模拟

Code

#include <iostream>
using namespace std;
int X, a, b, k, Y, points, days, training_streak;

int main() {
    cin >> X >> a >> b >> k >> Y;
    while (days <= X) {
        if (points >= Y) {
            cout << days << endl;
            return 0;
        }
        if (training_streak == k) {
            points -= b;
            training_streak = 0;
        }else{
            points += a;
            training_streak++;
        }
        days++;
    }
    cout<< -1 << endl;
    return 0;
}

C. Minecraft

以4为一组留下,剩下零散的拿去做棍子

Code

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

int n,a[200005];
int cnt,lt;
int get(int x){
    int ans =0;
    ans += x/5 *12;
    x %= 5;
    if(x>=2)ans += (x-1)*3;
    return ans;
}
int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        cnt += a[i]/4;
        lt += a[i]%4;
    }
    if(lt/2*2>=cnt){
        cout<<cnt*3;
    }else{
        cout<<lt/2*6+get(cnt-lt/2*2);
    }

    return 0;
}

D. Train

分析可知若L可行,则L+3也可行,找到最小的mod3=1 mod3=2 mod3=0的数,然后比其大的都可行,分析知只有2 3 5 6 8 11不可行

Code

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    if(n==2 or n==3 or n==5 or n==6 or n==8 or n==11)cout<<"NO";
    else cout<<"YES";
}

E. Simple Counting

好数对的充要条件是ak_1+bk_2=da有解

则根据飞鼠定理只要是同余gcd(k1,k2)的数对一定有解

那么只需要统计同余的数即可

Code

#include<bits/stdc++.h>
using namespace std;
int n,k1,k2,g;
long long ans;
map<int,int> mp;
int main(){
    cin>>n>>k1>>k2;
    g = __gcd(k1,k2);
    for(int i=0;i<n;i++){
        cin>>k1;
        mp[k1%g]++;
    }
    for(auto i:mp){
        ans += (long long)i.second*((long long)i.second-1)/2ll;
    }
    cout<<ans;
    return 0;
}

F. Sleepy Capoo

若L可行,则L-2也可行,找到以i开头最小的mod2=0 mod2=1的数,比其大的都可行

Code

 #include<bits/stdc++.h>
 using namespace std;
 void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n*2+1),s(n*2+1);
    for(int i=1;i<=n;++i){
        cin>>a[i];
        a[i+n]=a[i];
    }
    for(int i=1;i<=n*2;++i){
        s[i]=s[i-1]+a[i];
    }
    vector<int> nxt(n*2+2),pre(2*n+2);
    for(int i=1;i<=n*2;++i){
        pre[i]=a[i]==1?i:pre[i-1];
    }
    for(int i=2*n;i;--i){
        nxt[i]=a[i]==1?i:nxt[i+1];
    }
    while(m--){
        int x,c;cin>>x>>c;
        int r=x+n-1;
        int sum=s[r]-s[x-1],ok=0;
        if((sum-c)%2==0){
            ok=(c<=sum);
        }
        else{
            if(nxt[x]&&nxt[x]<=r){
                int t=s[r]-s[nxt[x]];
                if(c<=t) ok=1;
            }
            if(pre[r]&&pre[r]>=x){
                int t=s[pre[r]-1]-s[x-1];
                if(c<=t) ok=1;
            }
        }
        cout<<(ok?"YES":"NO")<<"\n";
    }
 }
 signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
 }
License:  CC BY 4.0