【HT-017-Div.4】核桃新手组周赛寄

· · 个人记录

每次打新手组都有一种自己唐了的感觉……

95+90+90+77=352,还行吧,该死的乐多。

T1

一开始想着就转一个货物,结果一交 60 WA。

using namespace std;
void swap(int &a, int &b)
{
    int t = a;
    a = b;
    b = t;
}
int main()
{
    int a1, b1, a2, b2;
    cin >> a1 >> b1 >> a2 >> b2;
    if (a1 > b1) swap(a1, b1);
    if (a2 > b2) swap(a2, b2);
    cout << min((a1+a2)*max(b1,b2), (b1+b2)*max(a1,a2));
    return 0;
}

只分类了两种情况,不 WA 才怪。

应该分四种情况:

  1. 两货物都不转
  2. 转第一个货物
  3. 转第二个货物
  4. 两个都转

四种情况选最小值即可。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a1, b1, a2, b2;
    cin >> a1 >> b1 >> a2 >> b2;
    int v1=(a1+a2)*max(b1,b2), v2=(a1+b2)*max(b1,a2), v3=(b1+a2)*max(a1,b2), v4=(b1+b2)*max(a1,a2);
    cout << min({v1,v2,v3,v4});
    return 0;
}

T2

一眼贪心,打了30min才拿了30pts

#include <bits/stdc++.h>
using namespace std;
struct node {
    int t;
    int r;
};
bool cmp(const node &a, const node &b) {
    return a.t < b.t;
}
int main() {
    int n;
    cin >> n;
    vector<node> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].t >> a[i].r;
    }
    sort(a.begin(), a.end(), cmp);
    vector<int> l(5, -1);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int t = a[i].t + 8;
        int r = a[i].r - 1;
        if (t > l[r]) {
            ans++;
            l[r] = t;
        }
    }
    cout << ans;
    return 0;
}

换了个贪心策略,算出每个僵尸到达第一行的时间,用了一个神奇的数据结构,结果还不是TLE。

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    map<int, map<int, int>> ra;
    for (int i = 0; i < n; ++i) {
        int t = a[i].first;
        int r = a[i].second;
        ra[r][t]++;
    }
    int ans = 0;
    for (auto& ra_i : ra) {
        map<int,int>& num = ra_i.second;
        while (!num.empty()) {
            auto maxnum = max_element(num.begin(), num.end(),
                                      [](const pair<int, int>& a, const pair<int, int>& b) {
                                          return a.second < b.second;
                                      }); //干脆改auto得了 
            ans++;
            int maxt = maxnum->first;
            num.erase(maxt);
        }
    }
    cout << ans;
    return 0;
}

于是就换了个好写的方法,换成了vector里套vector,然后……过了?!

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<vector<int>> r(5);
    for (int i = 0; i < n; ++i) {
        int t, rr;
        cin >> t >> rr;
        r[rr - 1].push_back(t);
    }
    int ans = 0;
    for (int i = 0; i < 5; ++i) {
        if (!r[i].empty()) {
            sort(r[i].begin(), r[i].end());
            int T = -1;
            for (int j = 0; j < r[i].size(); j++) {
                if (r[i][j] > T) {
                    ans++;
                    T = r[i][j] + 8;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

T3

鉴定为模拟,结果估计是真唐了,审题审两次都没审对,操作 % k 指的是留下 str_{0\dots k-1} 的部分,前两次都把 str_{0\dots k-1} 擦去了,再次含泪拿下90分

#include <bits/stdc++.h>
using namespace std;
string s = "";
int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        char op;
        cin >> op;
        if(op == '+')
        {
            string t;
            cin >> t;
            s += t;
        }
        else if (op == '*')
        {
            int t;
            cin >> t;
            string st = s;
            for (int i = 1; i < t; i++) s += st;
        }
        else
        {
            int k;
            cin >> k;
            if (k > s.length()) continue;
            s.erase(0,k);
        }
    }
    cout << s;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
string s = "";
int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        char op;
        cin >> op;
        if(op == '+')
        {
            string t;
            cin >> t;
            s += t;
        }
        else if (op == '*')
        {
            int t;
            cin >> t;
            string st = s;
            for (int i = 1; i < t; i++) s += st;
        }
        else if (op == '%')
        {
            int k;
            cin >> k;
            if (k > s.length()) continue;
            s.erase(k, s.length()-k);
        }
    }
    cout << s;
    return 0;
}

T4

一直以为是数学问题,结果写了5次都没过,后来才发现 1\leq n \leq 500 直接枚举即可。看来是真唐了,O(n^2) 稳过好吧。

#include <iostream>  
using namespace std;
int main() {  
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n-2; i++)
    {
        for (int j = 1; j <= n-2-i; j++)
        {
            int k = n-i-j;
            ans = max(i*j*k, ans);
        }
    }
    cout << ans;
    return 0;  
}