【HT-021-Div.4】核桃新手组周赛答案

<center>
<h2>第一题</h2>
</center>

#include <iostream>
using namespace std;

int main() {
    long long a, b, c;
    cin >> a >> b >> c;

    long long minCards = (c + b - 1) / b;

    long long maxCards = (c + a - 1) / a;

    cout << minCards << " " << maxCards << endl;

    return 0;
}

<center>
<h2>第二题</h2>
</center>

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],nu[1001]={};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        nu[a[i]]++;
    }
    int ans=0;
    while(nu[0])
    {
        int i=-1;
        while(++i<1001&&nu[i])
            nu[i]--;
        ans+=i;
    }
    cout<<ans;
}

<center>
<h2>第三题</h2>
</center>

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string k;
    int c=0,a[128]={0},maxx=0;
    cin >> k;
    for (int i=0;i<k.length();i++)
    {
        a[k[i]/1]++;
        maxx=max(maxx,a[k[i]/1]);
    }
    cout << maxx;
    return 0;
}

<center>
<h2>第四题</h2>
</center>

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

vector<vector<char>> rotate(const vector<vector<char>>& matrix) {
    int n = matrix.size();
    vector<vector<char>> result(n, vector<char>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            result[j][n - i - 1] = matrix[i][j];
        }
    }
    return result;
}

bool canFormWithStamp(int N, vector<vector<char>>& c, int K, vector<vector<char>>& stamp, int start_x, int start_y) {
    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < K; ++j) {
            if (stamp[i][j] == '*' && c[start_x + i][start_y + j] == '.') {
                return false;
            }
        }
    }
    return true;
}

void applyStamp(int N, vector<vector<char>>& c, int K, vector<vector<char>>& stamp, int start_x, int start_y) {
    for (int i = 0; i < K; ++i) {
        for (int j = 0; j < K; ++j) {
            if (stamp[i][j] == '*') {
                c[start_x + i][start_y + j] = '*';
            }
        }
    }
}

bool solve(int N, vector<vector<char>>& c, int K, vector<vector<vector<char>>>& stamps) {
    if (K > N) return false;

    vector<vector<char>> grid(N, vector<char>(N, '.'));

    for (int i = 0; i <= N - K; ++i) {
        for (int j = 0; j <= N - K; ++j) {
            for (auto& stamp : stamps) {
                if (canFormWithStamp(N, c, K, stamp, i, j)) {
                    applyStamp(N, grid, K, stamp, i, j);
                }
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (c[i][j] != grid[i][j]) return false;
        }
    }

    return true;
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;

        vector<vector<char>> c(N, vector<char>(N));
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                cin >> c[i][j];
            }
        }

        int K;
        cin >> K;

        vector<vector<char>> a(K, vector<char>(K));
        for (int i = 0; i < K; ++i) {
            for (int j = 0; j < K; ++j) {
                cin >> a[i][j];
            }
        }

        vector<vector<vector<char>>> stamps;
        stamps.push_back(a);
        for (int r = 0; r < 3; ++r) {
            stamps.push_back(rotate(stamps.back()));
        }

        if (solve(N, c, K, stamps)) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }

    return 0;
}

0 条评论

目前还没有评论...