雅礼总结8月25号

· · 个人记录

一、比赛基本情况

比赛日期:8月25日

比赛时长:3小30分

比赛得分:0分(250分)

比赛排名:倒数第1

二、比赛整体回顾

多写了sample文件

三、题目复盘

T1:____A - Photoshoot B____

本题得分:0(100)

开始时间:8:00

结束时间:8:25

总用时:25分钟

初始思路

这题我熟

考场解题过程

其实可以直接把2个捆绑然后判断不等就足够了

考场代码

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

int n;
string s;
vector<int> v;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    s = '@' + s;
    for(int i = 1; i < n; i += 2){
        if(s[i] == 'H' && s[i + 1] == 'G') v.push_back(0);
        else if(s[i] == 'G' && s[i + 1] == 'H') v.push_back(1);
    }
    int ans = 0;
    for(int i = 0; i < v.size() - 1; i++){
        if(v[i] != v[i + 1]) ans++;
//          cout << v[i] << "\n";
    }
    if(!v.empty()) ans += v.back();
    cout << ans;
    return 0;
}

复杂度

时间复杂度:O(n)

空间复杂度:O(n)

本题总结

无

T2:____B - Teleportation B____

本题得分:0(40)

开始时间:9:26

结束时间:9:30

总用时:4分

初始思路

考场解题过程

考场代码

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

int l, r, x, y;
signed main(){
    // freopen("teleport.in", "r", stdin);
    // freopen("teleport.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> l >> r >> x >> y;
    if(y < x) swap(x, y);
    cout << min(r - l, abs(l - x) + abs(r - y));
    return 0;
}

赛后题解

补题代码

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

int l, r, x, y;
signed main(){
    // freopen("teleport.in", "r", stdin);
    // freopen("teleport.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> l >> r >> x >> y;
    if(y < x) swap(x, y);
    if(r < l) swap(l, r);
    cout << min(r - l, abs(l - x) + abs(r - y));
    return 0;
}

复杂度

时间复杂度:O(1)

空间复杂度:O(1)

本题总结

细节(l > r)

邪恶出题人

T3:____C - Milk Scheduling S____

本题得分:0(100)

开始时间:8:26

结束时间:9:26

总用时:60

初始思路

贪心的话不一定,但是我们去掉一个拿起一个时间不变,可以尝试反悔贪心

考场解题过程

if(lst < num[i].b){
    ans += num[i].a;
    q.push(num[i].a);
    lst++;
}else if(tp < num[i].a){
    ans = ans - tp + num[i].a;
    q.pop();
    q.push(num[i].a);
}

考场代码

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

int n;
int const N = 2e5 + 5;
struct Node{
    int a, b;
} num[N];
bool cmp(Node x, Node y){
    return x.b < y.b;
}
priority_queue<int, vector<int>, greater<int>> q;
signed main(){
    // freopen("msched.in", "r", stdin);
    // freopen("msched.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> num[i].a >> num[i].b;
    }
    sort(num + 1, num + n + 1, cmp);
    int lst = 0, ans = 0;
    for(int i = 1; i <= n; i++){
        int tp = 0;
        if(!q.empty()) tp = q.top();
        if(lst < num[i].b){
            ans += num[i].a;
            q.push(num[i].a);
            lst++;
        }else if(tp < num[i].a){
            ans = ans - tp + num[i].a;
            q.pop();
            q.push(num[i].a);
        }
    }
    cout << ans << "\n";
    return 0;
}

复杂度

时间复杂度:O(nlogn)

空间复杂度:O(n)

本题总结

无

T4:____D - Umbrellas for Cows____

本题得分:0(10)

开始时间:9:30

结束时间:10:30

总用时:60

初始思路

无

赛后题解

其实我们其实可以发现这是对于dp[i] = 前i种的最小值

dp[i] = min(dp[i], dp[j - 1] + min(v[a[i] - a[j] + k + 1]])

min可以预处理

补题代码

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

int n, m;
int const N = 2e5 + 5;
int a[N], c[N], sub[N], dp[N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= m; i++) cin >> c[i];
    sub[m + 1] = 1e9;
    for(int i = m; i >= 1; i--) sub[i] = min(sub[i + 1], c[i]);
    sub[0] = sub[1];
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            dp[i] = min(dp[i], dp[j - 1] + sub[a[i] - a[j] + 1]);
        }
    }
    cout << dp[n];
    return 0;
}

复杂度

时间复杂度:O(n^2)

空间复杂度:O(n)

本题总结

四、整体反思

做得较好的地方

无

需要改进的地方

要注意细节和文件问题

时间安排总结

较好