2025年睿抗机器人开发者大赛CAIP-编程技能赛(国赛)-高职组 个人题解

 RC-v1 泼天的富贵

思路:

签到题

把公式化开即可得到

  

Code:

#include<bits/stdc++.h> 

using namespace std; 
const int N = 1e3 + 5;
int a[N], b[N];   
struct node { 
    int x, id;
} ;

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); 
    int n, d, k, tot = 0; cin >> n >> d >> k; 
    vector<node> info;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= d; j++) { 
            cin >> a[j]; 
            b[j] = 0;
        }
        int ans = 0;
        for (int j = 1; j <= d; j++) {
            if (a[j] > a[j - 1]) {
                b[j] = b[j - 1] + 1;
            } else {
                b[j] = 1;
            } 
        }     
        for (int j = 1; j <= d; j++) {    
            if (b[j] >= k) ans = max(ans, a[j] - a[j - k + 1]);
        }
        info.push_back({ans, i});
    }
    sort(info.begin(), info.end(), [&](auto x, auto y) -> bool {
        if (x.x == y.x) {
            return x.id < y.id;
        }
        return x.x > y.x;
    });  
    vector<int> idx;
    cout << info[0].x << '/' << k << '\n';
    for (auto i : info) {
        if (i.x == info[0].x) {
            idx.push_back(i.id);
        }
    }

    for (int i = 0; i < idx.size(); i++) {
        cout << idx[i] << " \n"[i == idx.size() - 1];
    }
    return 0;
}

  

  

RC-v2 行李运输

思路:

二分答案

Code:

#include<bits/stdc++.h> 

using namespace std;  
using LL = long long;

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);  

    int n, k; cin >> n >> k;
    vector<LL> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    LL L = *max_element(a.begin(), a.end()), R = 2e9, ans;
    while(L <= R) {
        LL mid = (L + R) >> 1;

        auto check = [&](LL x) -> bool {
            int S = 0, cnt = 0;
            for (int i = 1; i <= n; i++) {
                S += a[i];
                if (S > x) {
                    S = a[i];
                    cnt++;
                } 
            }
            return cnt + (S ? 1 : 0) <= k;
        } ;

        if (check(mid)) {
            R = mid - 1;
            ans = mid;
        } else {
            L = mid + 1;
        }
    }

    cout << ans << '\n';
    return 0;
}

  

 

RC-v3 自然倍树

 

Code:

#include<bits/stdc++.h> 

using namespace std; 
const int inf = 1e9;

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); 

    int t;
    cin >> t;
    while(t--) {
        int n; cin >> n;
        vector<int> pos(n), in(n);
        for (int i = 0; i < n; i++) cin >> pos[i];
        for (int i = 0; i < n; i++) cin >> in[i];
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            mp[in[i]] = i;
        }

        auto dfs = [&](auto &&self, int pl, int pr, int il, int ir, int dep) -> bool {
            if (pl > pr or il > ir) return true;

            int rt = pos[pr];
            if (rt % dep) {
                return false;
            }

            if (!self(self, pl, pl + mp[rt] - il - 1, il, mp[rt] - 1, dep + 1)) {
                return false;
            }
            if (!self(self, pl + mp[rt] - il, pr - 1, mp[rt] + 1, ir, dep + 1)) {
                return false;
            }

            return true; 
        } ;
        // cerr << 1 << '\n';
        if (dfs(dfs, 0, n - 1, 0, n - 1, 1)) {
            cout << 1 << '\n';
        } else {
            cout << 0 << '\n';
        } 
    }

    return 0;
}

  

RC-v4 留下买路财

思路:

地点1, 地点2, A, B
A, 地点1(from), 地点2(to) 各自为起点跑一次最短路 
注: (from, to)这条路免费  
得到关系式
1.A(起点)->B(终点)
2.A(起点)->from(终点), to(起点)->B(终点)
3.A(起点)->to(终点), from(起点)->B(终点)  

  

Code:

 

  

/*
地点1, 地点2, A, B
A, 地点1(from), 地点2(to) 各自为起点跑一次最短路 
注: (from, to)这条路免费  
得到关系式
1.A(起点)->B(终点)
2.A(起点)->from(终点), to(起点)->B(终点)
3.A(起点)->to(终点), from(起点)->B(终点)  
*/

#include<bits/stdc++.h> 

using namespace std; 
const int inf = 1e9;

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); 

    int n, m, k; cin >> n >> m >> k;
    vector<vector<array<int, 2>>> adj(n + 1);
    map<array<int, 2>, int> mp; 
    for (int i = 1; i <= m; i++) {
        int from, to, w; cin >> from >> to >> w;
        adj[from].push_back({w, to});
        adj[to].push_back({w, from});
        mp[{from, to}] = w;
        mp[{to, from}] = w;
    }
 
    auto dijkstra = [&](int s) -> vector<int> {
        vector<int> dist(n + 1, inf);
        vector<bool> vis(n + 1, 0);
        priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> pq;
        pq.push({0, s});
        dist[s] = 0;

        while(pq.size()) {
            auto [dw, from] = pq.top();
            pq.pop();
            if (vis[from]) {
                continue;
            }
            vis[from] = 1;
            for (auto [w, to] : adj[from]) {
                if (dist[to] > dist[from] + w) {
                    dist[to] = dist[from] + w;
                    pq.push({dist[to], to});
                }
            }
        }
        return dist;
    } ;
 
    while(k--) {    
        int from, to, A, B; cin >> from >> to >> A >> B;  
        auto D1 = dijkstra(A), D2 = dijkstra(from), D3 = dijkstra(to);
        int ans = inf;
        if (D1[B] < inf) ans = min(D1[B], ans);
        if (D1[from] < inf and D3[B] < inf) {
            ans = min(ans, D1[from] + D3[B] - mp[{from, to}]); 
        }

        if (D1[to] < inf and D2[B] < inf) {
            ans = min(ans, D1[to] + D2[B] - mp[{from, to}]); 
        } 
        if (ans >= inf) {
            cout << "@_@\n";
        } else {
            cout << max(0, ans) << '\n';
        }
    }

    return 0;
}

  

  2

 
posted @ 2025-08-23 23:43  Iter-moon  阅读(58)  评论(0)    收藏  举报