Codeforces Round #799 (Div. 4)(8/8)

Problem - A - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if (b > a){
      ans++;
    }
    if (c > a){
      ans++;
    }
    if (d > a){
      ans++;
    }
    cout << ans << endl;
  }
}

Problem - B - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int j = 0; j < n; j++){
      cin >> a[j];
    }
    sort(a.begin(), a.end());
    int cnt = unique(a.begin(), a.end()) - a.begin();
    if (cnt % 2 != n % 2){
      cnt--;
    }
    cout << cnt << endl;
  }
}

Problem - C - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    vector<string> S(8);
    for (int j = 0; j < 8; j++){
      cin >> S[j];
    }
    int r, c;
    for (int j = 1; j < 7; j++){
      for (int k = 1; k < 7; k++){
        int cnt = 0;
        for (int x = j - 1; x <= j + 1; x++){
          for (int y = k - 1; y <= k + 1; y++){
            if (S[x][y] == '#'){
              cnt++;
            }
          }
        }
        if (cnt == 5){
          r = j;
          c = k;
        }
      }
    }
    cout << r + 1 << ' ' << c + 1 << endl;
  }
}

Problem - D - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int h;
    char c;
    int m;
    int x;
    cin >> h >> c >> m >> x;
    int T = h * 60 + m;
    vector<bool> used(1440, false);
    used[T] = true;
    while (true){
      T += x;
      T %= 1440;
      if (used[T]){
        break;
      }
      used[T] = true;
    }
    int ans = 0;
    for (int j = 0; j < 1440; j++){
      if (used[j]){
        int hh = j / 60, mm = j % 60;
        if (mm / 10 == hh % 10 && mm % 10 == hh / 10){
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

Problem - E - Codeforces

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  for (int i = 0; i < t; i++){
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int j = 0; j < n; j++){
      cin >> a[j];
    }
    vector<int> p;
    p.push_back(-1);
    for (int j = 0; j < n; j++){
      if (a[j] == 1){
        p.push_back(j);
      }
    }
    p.push_back(n);
    int cnt = p.size() - 2;
    if (cnt < s){
      cout << -1 << endl;
    } else {
      int cnt = p.size();
      int ans = n;
      for (int j = 0; j < cnt - s - 1; j++){
        ans = min(ans, n - (p[j + s + 1] - p[j]) + 1);
      }
      cout << ans << endl;
    }
  }
}

Problem - F - Codeforces

AC代码:

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

void Solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cnt(10);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i] % 10]++;
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if (cnt[i] && cnt[j] && cnt[k]) {
                    cnt[i]--;
                    cnt[j]--;
                    cnt[k]--;
                    if (cnt[i] < 0 || cnt[j] < 0 || cnt[k] < 0) {
                        cnt[i]++;
                        cnt[j]++;
                        cnt[k]++;
                        continue;
                    }
                    int x = i + j + k;
                    if (x % 10 == 3) {
                        cout << "YES\n";
                        return;
                    }
                    cnt[i]++;
                    cnt[j]++;
                    cnt[k]++;
                }
            }
        }
    }
    cout << "NO\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - G - Codeforces

AC代码:

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

void Solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n;) {
        int cnt = 1;
        while (i < n && a[i - 1] < 2 * a[i]) {
            cnt++;
            i++;
        }
        if (cnt >= k + 1) {
            ans += cnt - k;
            cnt = 1;
            i++;
        }
        else {
            cnt = 1;
            i++;
        }
    }
    cout << ans << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

Problem - H - Codeforces

AC代码:

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

void Solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, vector<int>> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]].push_back(i);
    }
    map<int, vector<int>>::iterator it;
    int ans = 0, l = -1, r = -1, maxx = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
        int len = it->second.size();
        int tmp = -0x3f3f3f3f, pos;
        for (int i = 0; i < len; i++) {
            if (it->second[i] - 2 * i > tmp) {
                tmp = it->second[i] - 2 * i;
                pos = it->second[i];
            }
            int cnt = 2 * i - it->second[i] + tmp + 1;
            if (cnt > maxx) {
                maxx = cnt;
                ans = it->first;
                l = pos;
                r = it->second[i];
            }
        }
    }
    cout << ans << " " << l + 1 << " " << r + 1 << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值