2021CCCC天梯賽

golemon發表於2024-03-10

L1模擬+字串操作,L2讀題+簡單資料結構,L3題太長沒耐心(

L1-1

#include <bits/stdc++.h>
using namespace std;
int main()
{
    puts("To iterate is human, to recurse divine.");
}

L1-2

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c; cin>>a>>b>>c;
    cout<<max(0, a - b * c);
    
}

L1-3

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s; cin>>s;
    if(s.size() == 6) {
        cout<<s.substr(0, 4)<<'-'<<s.substr(4);
    } else {
        int a = stoi(s.substr(0,2));
        if(a < 22) {
            cout<<20<<s.substr(0,2)<<'-'<<s.substr(2);
        } else cout<<19<<s.substr(0,2)<<'-'<<s.substr(2);
    }
}

L1-4

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n; double m; cin>>n>>m;
    for(int i = 0; i < n; ++i) {
        double t; cin>>t;
        if(t < m) {
            cout<<"On Sale! ";
            printf("%.1lf\n",t);
        }
    }
}

L1-5

#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> a(25);
    for(int i = 1; i <= 24; ++i) cin>>a[i];
    int t;
    while(scanf("%d", &t), t >= 0 && t < 24) {
        cout<<a[t + 1]<<' '<<(a[t + 1] > 50 ? "Yes" : "No")<<endl;
    }
}

L1-6

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m; cin>>n>>m;
    cin.ignore();
    vector<string> s(n);
    for(auto &t: s) getline(cin, t);
    // for(auto &t: s) cout<<t<<endl;
    int now = 0;
    for(auto &t: s) {
        if(t.find("qiandao") == string::npos && t.find("easy") == string::npos) {
            if(now == m) {
                cout<<t<<endl;
                return 0;
            }
            ++now;
        }
    }
    cout<<"Wo AK le"<<endl;
}

L1-7

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin>>n;
    map<int,int> mp;
    for(int i = 0, t; i < n ; ++i) {
        cin>>t; mp[t]++;
    }
    auto pre = *mp.begin(), suf = *mp.rbegin();
    cout<<pre.first<<" "<<pre.second<<endl;
    cout<<suf.first<<" "<<suf.second<<endl;
}

L1-8

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b; cin>>a>>b;
    vector<int> v({0, a, b});
    int q; cin>>q;
    int pos = 1;
    while(q--) {
        int s = v[pos] * v[pos + 1];
        string t = to_string(s);
        for(auto &c: t) {
            v.push_back(c - '0');
        }
        cout<<v[pos]<<' ';
        ++pos;
    }
}

L2-1

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,k; cin>>n>>m>>k;
    vector<string> s(n);
    vector<int> p(n, 0);
    for(auto &t: s) cin>>t;
    int a;
    vector<char> st;
    while(scanf("%d", &a), ~a) {
        if(a == 0) {
            if(st.size() != 0) cout<<st.back(), st.pop_back();

        } else {
            --a;
            if(p[a] < m) {
                if(st.size() >= k)
                    cout<<st.back(), st.pop_back();
                st.push_back(s[a][p[a]++]);
            }
        }
    }
}

L2-2

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin>>n;
    vector<vector<int>> g(n);
    vector<int> in(n), d(n), son(n, -1);
    for(int i = 0; i < n ; ++i) {
        int k; cin>>k;
        while(k--) {
            int v; cin>>v; g[i].push_back(v);
            in[v]++;
        }
    }
    int root = 0;
    while(in[root]) ++root;
    auto dfs = [&](auto &&self, int u) -> void {
        son[u] = -1;
        for(auto &y: g[u]) {
            self(self, y);
            int t = d[y];
            if(d[u] < t) son[u] = y;
            else if(t == d[u]) son[u] = min(son[u], y);
            d[u] = max(d[u], t);
        }
        d[u]++;
    };
    dfs(dfs, root);
    cout<<d[root]<<endl;
    cout<<root<<' ';
    while(~son[root]) {
        cout<<(root = son[root])<<' ';
    }
}

L2-3

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    map<vector<int>, int> mp;
    for(int i = 0; i < n; ++i) {
        vector<int> t(m);
        for(int j = 0; j < m; ++j) cin>>t[j];
        mp[t]++;
    }
    vector<vector<int>> v;
    for(auto &t: mp) {
        vector<int> a;
        a.push_back(t.second);
        for(auto &x: t.first) a.push_back(x);
        v.push_back(a);
    }
    sort(v.begin(), v.end(),[&](auto pre, auto suf) {
        if(pre[0] != suf[0]) return pre[0] > suf[0];
        else {
            for(int i = 1; i < m + 1; ++i) {
                if(pre[i] != suf[i]) return pre[i] < suf[i];
            }
        }
    });
    cout<<v.size()<<endl;
    for(auto &t: v) {
        for(auto &x: t) cout<<x<<' '; cout<<endl;
    }

}

L2-4

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vector<int>> a(n + 1);
    for(int i = 1; i <= n; ++i) {
        int k; cin>>k;
        while(k--) {
            int x; cin>>x;
            a[i].push_back(x);
        }
    }
    vector<int> cur(121);
    int now = 1;
    for(int i = 1; i <= m; ++i) {
        int op,j; cin>>op>>j;
        if(op == 0) now = a[now][j - 1];
        if(op == 1) {
            cout<<now<<endl;
            cur[j] = now;
        } 
        if(op == 2) {
            now = cur[j];
        }
    }
    cout<<now<<endl;
}

相關文章