2023年春季西南民族大学プログラミングコンテスト 第6回 解説

問題解説 - L1-1 今日こそ勝利を掴む

この問題は単純な出力問題です。指定された文字列と日付を出力するだけです。

#include <iostream>
using namespace std;

void process() {
    cout << "I'm gonna win! Today!" << endl;
    cout << "2022-04-23" << endl;
}

問題解説 - L1-2 ダイヤモンドの植栽

整数nとvが与えられ、nをvで割った商を求める問題です。

void process() {
    int total, divisor;
    cin >> total >> divisor;
    cout << total / divisor << endl;
}

問題解説 - L1-3 図書館に入れるのは誰か

2人のスコアq1とq2が与えられ、基準値sa(安全基準)とpa(補助基準)に基づいて判断します。

int n, m, t, safety_limit, assist_limit, score1, score2;

void process() {
    cin >> safety_limit >> assist_limit >> score1 >> score2;
    
    if(score1 >= safety_limit && score2 >= safety_limit) {
        cout << score1 << "-Y " << score2 << "-Y" << endl;
        cout << "huan ying ru guan" << endl;
    }
    else if(score1 >= assist_limit) {
        cout << score1 << "-Y " << score2 << "-Y" << endl;
        cout << "qing 1 zhao gu hao 2" << endl;
    }
    else if(score2 >= assist_limit) {
        cout << score1 << "-Y " << score2 << "-Y" << endl;
        cout << "qing 2 zhao gu hao 1" << endl;
    }
    else if(score1 >= safety_limit) {
        cout << score1 << "-Y " << score2 << "-N" << endl;
        cout << "1: huan ying ru guan" << endl;
    }
    else if(score2 >= safety_limit) {
        cout << score1 << "-N " << score2 << "-Y" << endl;
        cout << "2: huan ying ru guan" << endl;
    }
    else {
        cout << score1 << "-N " << score2 << "-N" << endl;
        cout << "zhang da zai lai ba" << endl;
    }
}

問題解説 - L1-4 エイリアン救出作戦

n+mの階乗を計算する問題です。

void process() {
    int n, m;
    cin >> n >> m;
    long long result = 1;
    for(int i = 1; i <= n + m; i++) {
        result *= i;
    }
    cout << result << endl;
}

問題解説 - L1-5 幸運を試す

1から6までの数字が与えられ、各位置からn番目の数字を見つける問題です。

int n, m, t, safety_limit, assist_limit, score1, score2;
int numbers[6];

void process() {
    for(int i = 0; i < 6; i++) {
        cin >> numbers[i];
    }
    cin >> n;
    
    for(int pos = 0; pos < 6; pos++) {
        int remaining = n;
        for(int digit = 6; digit > 0; digit--) {
            if(digit == numbers[pos]) continue;
            remaining--;
            if(remaining == 0) {
                cout << digit << (pos == 5 ? "\n" : " ");
                break;
            }
        }
    }
}

問題解説 - L1-6 ストックホルム列車の問題

文字列の隣接する文字が同じ偶奇を持つ場合、大きい方の文字を取り出す処理です。

void process() {
    string input1, input2, output1 = "", output2 = "";
    cin >> input1 >> input2;
    
    for(int i = 1; i < input1.length(); i++) {
        if(input1[i] % 2 == input1[i-1] % 2) {
            output1 += max(input1[i], input1[i-1]);
        }
    }
    
    for(int i = 1; i < input2.length(); i++) {
        if(input2[i] % 2 == input2[i-1] % 2) {
            output2 += max(input2[i], input2[i-1]);
        }
    }
    
    if(output1 == output2) {
        cout << output1 << endl;
    } else {
        cout << output1 << endl << output2 << endl;
    }
}

問題解説 - L1-7 メカニックスタジオ

ボスが攻撃する行と列を記録し、未攻撃のマス目を数える問題です。

int row_status[N], col_status[N];

void process() {
    cin >> n >> m >> q;
    int initial_total = n * m;
    int queries = q;
    
    while(q--) {
        int type, index;
        cin >> type >> index;
        
        if(type) {  // column
            if(!col_status[index]) m--;
            col_status[index] = 1;
        } else {    // row
            if(!row_status[index]) n--;
            row_status[index] = 1;
        }
    }
    
    cout << n * m << endl;
}

問題解説 - L1-8 静かな推薦

特定の条件を満たす学生をソートして数える問題です。

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_SIZE = 1e5+10;

struct StudentScore {
    int height;
    int score;
    bool operator < (const StudentScore &s) const {
        if(height != s.height) return score < s.score;
        return height < s.height;
    }
};

vector<StudentScore> scores(MAX_SIZE);
int count_array[MAX_SIZE];

void process() {
    int n, k, min_score;
    cin >> n >> k >> min_score;
    
    int result = 0;
    for(int i = 0; i < n; i++) {
        int h, s;
        cin >> h >> s;
        if(h >= 175 && s >= min_score) {
            result++;
            continue;
        }
        scores.push_back({h, s});
    }
    
    sort(scores.begin(), scores.end());
    
    int max_height = 0;
    for(int i = 0; i < scores.size(); i++) {
        if(scores[i].height < 175) continue;
        max_height = max(max_height, scores[i].height);
        count_array[scores[i].height - 175]++;
    }
    
    max_height -= 175;
    for(int i = 0; i <= max_height; i++) {
        if(count_array[i] >= k) result += k;
        else result += count_array[i];
    }
    
    cout << result << endl;
}

問題解説 - L2-1 松の枝挿入

詳細な問題内容が提供されていませんが、松の枝に関する操作を行う問題です。

問題解説 - L2-2 社長のスケジュール表

時間を秒に変換してソートし、連続していない時間帯を出力する問題です。

bool visited[N], status[N];
vector<pair<long long, long long>> time_ranges;

void process() {
    cin >> n;
    time_ranges.push_back({0, 0});
    time_ranges.push_back({24 * 60 * 60 - 1, 24 * 60 * 60 - 1});
    
    while(n--) {
        char separator1, separator2, separator3, separator4, separator5;
        int start_hour, end_hour, start_minute, end_minute, start_second, end_second;
        cin >> start_hour >> separator1 >> start_minute >> separator2 >> start_second 
            >> separator3 >> end_hour >> separator4 >> end_minute >> separator5 >> end_second;
        
        time_ranges.push_back({
            (start_hour * 60 + start_minute) * 60 + start_second,
            (end_hour * 60 + end_minute) * 60 + end_second
        });
    }
    
    sort(time_ranges.begin(), time_ranges.end());
    
    for(int i = 1; i < time_ranges.size(); i++) {
        if(time_ranges[i].first == time_ranges[i-1].second) continue;
        
        int current_h = time_ranges[i].first / (60 * 60);
        int current_m = (time_ranges[i].first % 3600) / 60;
        int current_s = time_ranges[i].first % 60;
        
        int prev_h = time_ranges[i-1].second / (60 * 60);
        int prev_m = (time_ranges[i-1].second % 3600) / 60;
        int prev_s = time_ranges[i-1].second % 60;
        
        printf("%02d:%02d:%02d - ", prev_h, prev_m, prev_s);
        printf("%02d:%02d:%02d\n", current_h, current_m, current_s);
    }
}

問題解説 - L2-3 ドラゴン配送サービス

配送経路の最適化に関する問題ですが、詳細な内容は提供されていません。

問題解説 - L2-4 万人の恋人

人気度や好みの一致に関する問題ですが、詳細な内容は提供されていません。

タグ: competitive-programming Algorithm cpp contest problem-solving

7月9日 21:52 投稿