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