牛客小白月赛53

简介: 笔记

A Raining


void solve() {
    int a[4], b[4] = {0};
    for (int i = 0; i <= 3; i++) {cin >> a[i]; }
    int x;  cin >> x;
    for (int i = 0; i <= 3; i++) {
        if(a[i] < x) b[i] = x - a[i];
    }
    for (int i = 0; i <= 3; i++) {cout << b[i] << ' '; }
}

B Kissing


  • 化简
s = int(input())
mod = 998244353
print(s % mod * s % mod)


C Missing


题目

1.png

代码

  • 赛后
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    int n; cin >> n;
    vector<string> a[11];
    auto f = [&](string A){
        int res = 0;
        for (int i = 0; i < s.size(); i++) res += (A[i] == s[i]);
        if(A.size() != s.size()) res = 0;
        return res;
    };
    for (int i = 0; i < n; i++) {
        string t; cin >> t;
        a[f(t)].push_back(t);
    }
    for (int i = 10; i >= 0; i--) {
        if(a[i].size()) {
            sort(a[i].begin(), a[i].end());
            for (auto &x: a[i]) cout << x << endl;
            break;
        }
    }
    return 0;
}


  • 赛时,没想到用相似度索引。
string s[N];
double b[N];
map<string, double> mp;
void solve() {
  string a; cin >> a;
  int n; cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    if(s[i].sz != a.sz) continue;
    for (int j = 0; j < s[i].sz; j++) {
      if(s[i][j] == a[j]) cnt++;
    }
    b[i] = cnt * 1.0 / s[i].sz;
    mp[s[i]] = b[i];
  }
  sort(s, s + n, [=](string i, string j){
    if(mp[i] == mp[j]) return i < j;
    return mp[i] > mp[j];
  });
  cout << s[0] << endl;
  for (int i = 1; i < n; i++) {
    if(mp[s[i]] != mp[s[0]]) break;
    cout << s[i] << endl;
  }
}

D Breezing


题目

2.png

代码3.png

int n;
int a[N];
int dp[N][2];
void solve() {
  cin >> n; 
    for (int i = 1; i <= n; i++) cin >> a[i];
    dp[1][0] = dp[1][1] = 0;
    for (int i = 2; i <= n; i++) {
//         if(dp[i - 1][0] > dp[i - 1][1] + a[i - 1] - 1) dp[i][0] = dp[i - 1][0];
//         else dp[i][0] = dp[i - 1][1] + a[i - 1] - 1;
//         if(dp[i - 1][0] + a[i] - 1 > dp[i - 1][1] + abs(a[i - 1] - a[i])) dp[i][1] = dp[i - 1][0] + a[i] - 1;
//         else dp[i][1] = dp[i - 1][1] + abs(a[i - 1] - a[i]);
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + a[i - 1] - 1);
        dp[i][1] = max(dp[i - 1][0] + a[i] - 1, dp[i - 1][1] + abs(a[i] - a[i - 1]));
    }
    cout << max(dp[n][1], dp[n][0]) << endl;
}

E Calling


题目

4.png

代码

  • 先算得3、4、5、6装下所需要得大正方形个数res。
  • 在算得剩余空位能装2的个数res2,如果 a[2] > res2,换大正方形装2。
  • 如此算1。
#include <iostream>
using namespace std;
int main() {
    int t; cin >> t;
    while(t--) {
        int a[7] = {0};
        int n; cin >> n;
        for (int i = 1; i <= 6; i++) cin >> a[i];
        int res = 0;
        for (int i = 4; i <= 6; i++) res += a[i];
        res += (a[3] + 3) / 4;
        int res2 = a[4] * 5;
        if(a[3] % 4 == 1) res2 += 5;
        else if(a[3] % 4 == 2) res2 += 3;
        else if(a[3] % 4 == 3) res2 += 1;
        if(a[2] > res2) res += (a[2] - res2 + 8) / 9;
        int res1 = res * 36;
        for (int i = 2; i <= 6; i++) res1 -= a[i] * i * i;
        if(a[1] > res1) res += (a[1] - res1 + 35) / 36;
        puts(n >= res ? "Yes" : "No");
    }
    return 0;
}

F Freezing

相关文章
|
6月前
|
人工智能 BI
牛客小白月赛66
牛客小白月赛66
38 0