Martian148's blog Martian148's blog
首页
  • ICPC 算法笔记
  • ICPC 算法题解
  • 体系结构
  • 高等数学
  • 线性代数
  • 概率论与数理统计
  • 具体数学
  • Martian148的奇思妙想
  • 游记
  • 通识课笔记
关于
  • useful 网站
  • 友情链接
  • 分类
  • 归档

Martian148

一只热爱文科的理科生
首页
  • ICPC 算法笔记
  • ICPC 算法题解
  • 体系结构
  • 高等数学
  • 线性代数
  • 概率论与数理统计
  • 具体数学
  • Martian148的奇思妙想
  • 游记
  • 通识课笔记
关于
  • useful 网站
  • 友情链接
  • 分类
  • 归档
  • codeforses 题解

  • atcoder 题解

  • XCPC 题解

    • ICPC2023 合肥区域赛 题解
    • ICPC2024 武汉邀请赛 题解
    • ICPC2024 江西省赛 题解
    • ICPC2024 网络赛 第一场 题解
      • A - World Cup
        • Solution
        • Code
      • C - Permutation Counting 4
        • Solution
        • Code
        • summary
      • M - Find the Easiest Problem
        • Code
    • CCPC2023 哈尔滨站 题解
    • CCPC2023 桂林站 题解
    • CCPC2023 秦皇岛站 题解
    • CCPC2024 哈尔滨站 题解
  • 校训练赛题解

  • 牛客题解

  • 蓝桥杯题解

  • 典题选讲

  • 杂题

  • 算法题解
  • XCPC 题解
martian148
2024-10-25
目录

ICPC2024 网络赛 第一场 题解

# ICPC2024 网络赛 第一场

The 2024 ICPC Asia East Continent Online Contest (I) (opens new window)

# A - World Cup

# Solution

画个图分析一下就好了

# Code

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

struct Node {
    int val, id;
    bool operator < (const Node &B) const{
        return val < B.val;
    }
};

bool is_ok(vector<Node> &a) {
    for (auto v : a) {
        if (v.id == 1) return true;
    }
    return false;
}

void solve() {
    vector<Node> a(33);
    for (int i = 1; i <= 32; i++) cin >> a[i].val, a[i].id = i;
    sort(a.begin() + 1, a.end());
    int cnt = 0;
    for (int i = 1; i <= 32; i++) {
        if (a[i].id == 1) {
            cnt = i - 1;
        }
    }
    if (cnt >= 31) cout << 1;
    else if (cnt >= 27) cout << 2;
    else if (cnt >= 13) cout << 4;
    else if (cnt >= 6) cout << 8;
    else if (cnt >= 2) cout << 16;
    else cout << 32;
    cout << '\n';
}

int main() {
    freopen ("A.in", "r", stdin);
    ios::sync_with_stdio(false);
    int T; cin >> T;
    while (T--) solve();
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

# C - Permutation Counting 4

# Solution

一个没怎么道理的解法

对于一对 [l,r][l,r][l,r] ,从 l→r+1l\rightarrow r+1l→r+1 连边,如果最后的图为一棵树,那么答案为 111 否则为 000

# Code

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

void solve() {
    int n; cin >> n;
    vector<int> a(n + 2, 0);
    iota(a.begin(), a.end(), 0);

    function<int(int)> find = [&] (int x) -> int {
        return a[x] == x ? x : a[x] = find(a[x]);
    };

    function<void(int, int)> merge = [&] (int x, int y) {
        if (find(x) == find(y)) return;
        a[find(x)] = find(y);
    };

    vector<pair<int, int>> p(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;

    for (int i = 1; i <= n; i++) {
        auto [l, r] = p[i];
        if (find(l) == find(r + 1)) {
            cout << "0\n";
            return;
        }
        merge(l, r + 1);
    }
    set<int> st;
    for (int i = 1; i <= n + 1;  i++) st.insert(find(i));

    if (st.size() == 1) cout << "1\n";
    else cout << "0\n";
}

int main() {
    freopen ("C.in", "r", stdin);
    ios::sync_with_stdio(false);
    int T; cin >> T;
    while (T--) solve();
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

# summary

  • 对于答案为 01,应该从 YES/NO 的角度去思考,不应该从算总数的角度去考虑

# M - Find the Easiest Problem

# Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 5;
const ll MOD = 998244353;
ll Tex, n, a[MAXN];
ll fastPow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}
string s, t, p;
void AC(){
    cin >> n;
    map<pair<string, string>, ll> mp1;
    map<string, ll> mp2;
    ll mx = 0;
    for(int i = 1; i <= n; i ++){
        cin >> s >> t >> p;
        if(p == "accepted"){
            if(!mp1[{s, t}]){
                mp2[t] ++;
                mx = max(mp2[t], mx);
            }
            mp1[{s, t}] = 1;
        }
    }
    vector<string> ans;
    for(auto it : mp2){
        if(it.second == mx) ans.push_back(it.first);
    }
    sort(ans.begin(), ans.end());
    cout << ans[0] << '\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin >> Tex;
    while(Tex --) AC();
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
上次更新: 2025/04/08, 18:03:31
ICPC2024 江西省赛 题解
CCPC2023 哈尔滨站 题解

← ICPC2024 江西省赛 题解 CCPC2023 哈尔滨站 题解→

最近更新
01
Java基础语法
05-26
02
开发环境配置
05-26
03
pink 老师 JavaScript 学习笔记
05-26
更多文章>
Theme by Vdoing | Copyright © 2024-2025 Martian148 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式