碼蹄杯第三場專科賽道vp

Iter-moon發表於2024-06-29

A.MC0327神秘的儀式

題意:

三個整數(a, b, c) a + b > c輸出yes 否則輸出 no

Code:

#include<bits/stdc++.h>
    
using namespace std;
    
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b, c; cin >> a >> b >> c;
    cout << (a + b > c ? "yes" : "no");
    return 0;
}

B.MC0328小碼哥的式子

題意:

三個整數(a, b, c) 輸出 a * b % c

Code:

#include<bits/stdc++.h>
    
using namespace std;
    
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b, c; cin >> a >> b >> c;
    cout << a * b % c;
    return 0;
}

C.MC0329都市路徑(最短路)

題意:

起點是1 如果能達到其他點則輸出最小的距離d,否則輸出-1,模板題

Code:

#include<bits/stdc++.h>
    
using namespace std;
typedef pair <int, int> pii;
const int N = 1e2 + 5;
int n, d[N]; 
vector <pii> adj[N];
bool vis[N]; 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int from, t; cin >> from >> t;
        while (t--) {
            int to; cin >> to;
            adj[from].push_back({to, 1});
        }
    }
    priority_queue <pii, vector <pii>, greater <pii>> pq;
    for (int i = 1; i <= n; i++) d[i] = 250;
    pq.push({1, 0}); d[1] = 0;
    while (!pq.empty()) { 
        auto [from, w] = pq.top(); pq.pop();
        if (vis[from]) continue;
        vis[from] = 1;
        for (auto [to, w] : adj[from]) {
            if (d[to] > d[from] + w) {
                d[to] = d[from] + w;
                pq.push({to, d[to]});
            } 
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << (d[i] == 250 ? -1 : d[i]) << '\n';
    }
    return 0; 
}

  

D.MC0330奇怪的數

題意:

如果所有位數加起來等於10就計數加一,由於資料很小直接從1開始了

Code:

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

bool check(int x) {
    int res = 0;
    while (x) res += x % 10, x /= 10;
    return res == 10;
}
    
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, ans = 0; cin >> n;
    for (int i = 1; i <= n; i++) if (check(i)) ans ++;
    cout << ans << '\n';
    return 0;
}

  

相關文章