首页 > 其他分享 >2022ccpc威海(2022 China Collegiate Programming Contest (CCPC) Weihai Site)

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

时间:2022-12-08 17:23:13浏览次数:84  
标签:Weihai int 2022ccpc Contest cin Point i64 ++ using

链接: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;
}

标签:Weihai,int,2022ccpc,Contest,cin,Point,i64,++,using
From: https://www.cnblogs.com/kiddingma/p/16966655.html

相关文章

  • [Leetcode Weekly Contest]322
    链接:LeetCode[Leetcode]2490.回环句句子是由单个空格分隔的一组单词,且不含前导或尾随空格。例如,"HelloWorld"、"HELLO"、"helloworldhelloworld"都是符合要求的......
  • 【题解】The 2022 ICPC Asia Hangzhou Regional Programming Contest (第 47 届 ICPC
    D.MoneyGame一开始有\(n\)个人围成一圈,第\(i\)个人手上有\(a_i\)的存款(实数),每一轮从第一个人开始,每个人把自己手上的一半存款给下一个人,问稳定时每个人手上存款......
  • The 2022 ICPC Asia Xian Regional Contest B
    B.CellsColoring题链转化题意就是将这些'.'点分成两类第一类就是一个组内每个点都不在同行同列这样一组的贡献就是c第二类就是一些个没被选上的散点每个贡献是d我......
  • AtCoder Beginner Contest 280
    A-PawnonaGrid(abc280a)题目大意给定一个矩形格子,问#的数量。解题思路直接统计即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=......
  • AtCoder Beginner Contest 280 A-F
    AtCoderBeginnerContest280A-Fhttps://atcoder.jp/contests/abc280个人认为D>>E,F被D搞心态了,导致EF都没看()A-PawnonaGrid统计#的个数#include<bits/stdc......
  • AtCoder Beginner Contest 280
    D-FactorialandMultiple对\(k\)进行质因数分解。如果\(k\)最大的质因子\(p\)满足\(p*p>k\),那么答案就是\(p\)。因为一定要包含一次,也只需要包含一次。......
  • AtCoder Beginner Contest 280
    D-FactorialandMultiple数论  首先上这道题需要的数论知识:n!的素因子分解中,n!=p1^a1*p2^a2*p3^a3*.....*pk^ak中对于素因数pi,其对于的ai=n/pi+n/p......
  • AtCoder Beginner Contest 280 题解
    A-PawnonaGrid看样例猜题意(要求的是#的数量,直接判断。//If,oneday,Ifinallymanagetomakemydreamsareality...//Iwonder,willyoustillbethere......
  • AtCoder Beginner Contest 280 D-E
    D-FactorialandMultiple前置知识\(n!\)中包含素因子\(p\)的个数为\[cnt=\sum\limits_{k\geq1}^{p^k\leqn}\lfloor\frac{n}{p^k}\rfloor\]例如:\(n!\)......
  • The 2021 ICPC Asia Shanghai Regional Programming Contest I
    I.SteadilyGrowingSteam题链看完题发现可以暴力dp最开始想的状态就是dp[i][j][k]就是左边已经i权重右边已经j权重并且用了k次乘二的maxv然后我们时间复杂度算接近1e......