[UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312) - AtCoder](https://atcoder.jp/contests/abc312)

发布时间 2023-07-30 22:51:36作者: Ke_scholar

UNIQUE VISION Programming Contest 2023 Summer(AtCoder Beginner Contest 312) - AtCoder

A - Chord (atcoder.jp)

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {

    vector<string> str {"ACE","BDF","CEG","DFA","EGB","FAC","GBD"};
    string s;
    cin >> s;
    if(std::find(str.begin(), str.end(),s) != str.end()){
        cout << "Yes" << endl;
    }else
        cout << "No" << endl;

    return 0;
}

B - TaK Code (atcoder.jp)

模拟

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {

    int n,m;
    cin >> n >> m;
    vector<string> g(n);
    for(auto &i : g) cin >> i;

    auto check = [&](int x, int y){
        for(int i = x;i < x + 3;i ++)
            for(int j = y;j < y + 3;j ++)
                if(g[i][j] != '#' || g[i + 6][j + 6] != '#')
                    return false;

        for(int i = 0;i < 4;i ++)
            if(g[x + 3][y + i] != '.' || g[x + i][y + 3] != '.' || g[x + 5][y + 5 + i] != '.' || g[x + 5 + i][y + 5] != '.')
                return false;

        return true;
    };

    for(int  i = 0;i <= n - 9;i ++)
        for(int j = 0;j <= m - 9;j ++)
            if(check(i,j))
                cout << i + 1 << ' ' << j + 1 << endl;

    return 0;
}

C - Invisible Hand (atcoder.jp)

题意:

苹果市场上有\(N\)个卖家和\(M\)个买家。

\(i\) 个卖家可能会以 \(A_i\) 日元或更高的价格(日元是日本的货币)卖出一个苹果。

\(i\) 个买方可以以 \(B_i\) 日元或更低的价格购买一个苹果。

求满足以下条件的最小整数 \(X\)

条件:可以用\(X\)日元卖出一个苹果的人数大于或等于可以用\(X\)日元买入一个苹果的人数。

题解:

\(X\)日元能卖出的,则价格\(X\)日元以下的商家也愿意卖出,\(X\)日元能买的,则预算\(X\)日元以上的的买家也能买

\(X = A_i(1 \leq i \leq N) = B_j(1 \leq j\leq M)\),也就是要满足\(M - j \leq i\),就是说在\(A + B\)里寻找第\(M\)小的即可,

当然当所有卖家的意愿价格大于了所有买家的的预算,就说明没人愿意卖也没人愿意买,这时候最小\(X\)就是\(B\)里买家的最大预算+1,所以我们把\(A\)\(B\)和并的时候直接把\(B\)中所有元素都+1即可.

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {

    int n,m;
    cin >> n >> m;
    vector<int> a(n + m);
    for(int i = 0;i < n;i ++)
        cin >> a[i];
    for(int i = 0;i < m;i ++){
        cin >> a[i + n];
        a[i + n]++;
    }

    nth_element(a.begin(),a.begin() + m - 1,a.end());
    cout << a[m - 1] << endl;//从0开始的所以是m - 1
    
    return 0;
}