1. 程式人生 > 其它 >2022ccpc威海(2022 China Collegiate Programming Contest (CCPC) Weihai Site)

2022ccpc威海(2022 China Collegiate Programming Contest (CCPC) Weihai Site)

連結:https://codeforces.com/gym/104023

A. Dunai

簽到

C++ Code
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
  int n;
  cin >> n;
  set<string> st;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      string s;
      cin >> s;
      st.insert(s);
    }
  }
  int m;
  cin >> m;
  int ans = 0;
  vector<int> cnt(5);
  for (int i = 0; i < m; i++) {
    string s;
    int num;
    cin >> s >> num;
    cnt[num - 1]++;
    if (st.find(s) != st.end()) {
      ans++;
    }
  }
  for (int i = 0; i < 5; i++) {
    ans = min(ans, cnt[i]);
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

C. Grass

找不五點共線的五個點就行。

然後就看是哪個點作為 \(A\) 點,列舉一下就行。

C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

using Real = i64;

using Point = complex<Real>;

#define x real
#define y imag

struct Line {
  Point a, b;
  Line(const Point &a, const Point &b) : a(a), b(b) {}
};

struct Segment : Line {
  Segment() = default;
  using Line::Line;
};

Real cross(const Point &a, const Point &b) { return (conj(a) * b).y(); }

Real dot(const Point &a, const Point &b) { return (conj(a) * b).x(); }

bool onLine(const Point &p, const Line &l) {
  return cross(p - l.a, p - l.b) == 0;
}

bool onSegment(const Point &p, const Segment &l) {
  return cross(p - l.a, l.b - l.a) == 0 && dot(p - l.a, p - l.b) <= 0;
}

void solve() {
  int n;
  cin >> n;
  vector<Point> a(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = Point(x, y); 
  }
  if (n < 5) {
    cout << "NO" << '\n';
    return;
  }
  vector<Point> ans{a[0], a[1], a[2], a[3]};
  Line L(a[0], a[1]);
  for (int i = 4; i < n; i++) {
    if (!(onLine(a[2], L) && onLine(a[3], L) && onLine(a[i], L))) {
      cout << "YES" << '\n';
      ans.push_back(a[i]);
      for (int j = 0; j < 5; j++) {
        bool ok = 1;
        for (int k = 0; k < 5; k++) {
          if (j == k) {
            continue;
          }
          Segment S(ans[j], ans[k]);
          for (int now = 0; now < 5; now++) {
            if (now == j || now == k) {
              continue;
            }
            if (onSegment(ans[now], S)) {
              ok = 0;
              break;
            }
          }
          if (!ok) {
            break;
          }
        }
        if (ok) {
          cout << ans[j].x() << ' ' << ans[j].y() << '\n';
          for (int k = 0; k < 5; k++) {
            if (k == j) {
              continue;
            }
            cout << ans[k].x() << ' ' << ans[k].y() << '\n';
          }
          return;
        }
      }
    }
  }
  cout << "NO" << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

E. Python Will be Faster than C++

簽到

C++ Code
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[n - 1] >= a[n - 2]) {
    cout << "Python will never be faster than C++";
  } else {
    cout << "Python 3." << n + (a[n - 1] - m) / (a[n - 2] - a[n - 1]) + 1 << " will be faster than C++";
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

G. Grade 2

打表發現迴圈節是 \(2^{\lceil logn\rceil}\)

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  i64 x, n;
  cin >> x >> n;
  int lg = __lg(x);
  while ((1 << lg) < x) {
    lg++;
  }
  i64 bk = (1 << lg);
  vector<i64> a(bk);
  for (int i = 0; i < bk; i++) {
    if (gcd((i * x) ^ x, x) == 1) {
      a[i]++;
    }
  }
  for (int i = 1; i < bk; i++) {
    a[i] += a[i - 1];
  }
  auto get = [&](i64 x) {
    i64 cnt = x / bk;
    int add = x % bk;
    return a[bk - 1] * cnt + a[add];
  };
  for (int i = 0; i < n; i++) {
    i64 l, r;
    cin >> l >> r;
    cout << get(r) - get(l - 1) << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}

J. Eat, Sleep, Repeat

手玩一下,每個數有變化的範圍,比如限制 \(1\) 的出現次數為 \(0\),那麼就比他大的最多隻能減到 \(2\),然後如果限制 \(2\) 的出現次數為 \(1\),那麼現在就不能再減到 \(2\) 了,實現一下就行。

C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  priority_queue<int, vector<int>, greater<>> q;
  map<int, int> mp;
  for (int i = 0; i < k; i++) {
    i64 xi, yi;
    cin >> xi >> yi;
    if (yi == 0) {
      q.push(xi + 1);
    } else {
      mp[xi] = yi;
    }
  }
  i64 ans = 0;
  i64 now = 0;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    while (!q.empty() && q.top() <= a[i]) {
      now = q.top();
      q.pop();
    }
    ans += (a[i] - now);
    mp[now]--;
    if (mp[now] == 0) {
      q.push(now + 1);
    }
  }
  cout << (ans % 2 ? "Pico" : "FuuFuu") << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(6);
  int tt = 1;
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}