8.26_407_课堂总结

· · 个人记录

T639104 信奥大联赛

\color{#52c41a} 100pts

思路

排序

代码

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

struct User{
    string name;
    int s;
} a[101];

bool cmp(User a, User b){
    return a.name < b.name;
} 

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].name >> a[i].s;
        sum += a[i].s;
    }
    stable_sort(a + 1, a + n + 1, cmp);
    cout << a[sum % n + 1].name;
    return 0;
}

T660516 来追梦运动会之慢跑赛

\color{#52c41a} 100pts

思路

模拟

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, A, b, c, C, d, D, e, f, F, x, lld = 0, qg = 0;
    cin >> a >> b >> c >> d >> e >> f >> x;
    A = a, C = c, D = d, F = f;
    for(int i = 1; i <= x; i++){
        if(a){
            a--, lld += b;
        }else{
            c--;
        }
        if(!c && !a){
            c = C, a = A;
        }
        if(d){
            d--, qg += e;
        }else{
            f--;
        }
        if(!f && !d){
            f = F, d = D;
        }
    }
    if(lld == qg){
        cout << "Draw";
    }else if(lld > qg){
        cout << "Takahashi";
    }else{
        cout << "Aoki";
    }
    return 0;
}

T642548 引爆炸弹

\color{#52c41a} 100pts

思路

DFS

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool a[1001][1001];
int n, m, cnt;

void dfs(int x, int y){
    a[x][y] = 0;
    for(int i = 1; i <= n; i++){
        if(a[i][y]){
            dfs(i, y);
        }
    }
    for(int i = 1; i <= m; i++){
        if(a[x][i]){
            dfs(x, i);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            char c;
            cin >> c;
            if(c == '1'){
                a[i][j] = 1;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j]){
                cnt++;
                dfs(i, j);
            }
        }
    }
    cout << cnt;
    return 0;
}

T642551 卡牌

\color{#e74c3c} 0pts

时间不够QAQ

思路

用一个桶(map)存每个数字的数量,循环遍历,如果有就减一,否则退出

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<int, int> mp;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++){
            int x;
            cin >> x;
            mp[x]++;
        }
        int ans = 0;
        while(mp.size()){
            ans++;
            int xx;
            for(auto x : mp){
                xx = x.first;
                break;
            }
            mp[xx]--;
            if(!mp[xx]){
                mp.erase(xx);
            }
            int i = xx;
            while(1){
                i++;
                if(mp.count(i)){
                    mp[i]--;
                    if(!mp[i]){
                        mp.erase(i);
                    }
                }else{
                    break;
                }
            }
        }
        cout << ans << "\n";
    }
    return 0;
}