链接:
https://codeforces.com/gym/103941
A
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
int n;
cin >> n;
if (n > 10) {
cout << -1 << '\n';
} else if (n == 1) {
cout << 1;
} else if (n == 2) {
cout << 10;
} else {
cout << 10;
for (int i = 2; i <= n - 1; i++) {
cout << i;
}
}
}
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;
}
D
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
using d64 = long double;
using Point = pair<double, double>;
const double Pi = acos(-1);
#define x first
#define y second
void solve() {
int n;
cin >> n;
vector<Point> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].y;
}
Point center;
cin >> center.x >> center.y;
vector<Point> b(4);
for (int i = 0; i < 4; i++) {
cin >> b[i].x >> b[i].y;
}
vector<d64> d(2);
for (int i = 0; i < 2; i++) {
int I = i * 2, J = i * 2 + 1;
d[i] = fabs(
(d64) (b[I].y - b[J].y) * center.x - (d64) (b[I].x - b[J].x) * center.y + (d64) b[I].x * b[J].y - (d64) b[I].y * b[J].x
) / hypot<d64>(b[I].x - b[J].x, b[I].y - b[J].y);
}
double ans = 0;
vector<array<double, 2>> c;
auto push = [&](double l, double r, double now) {
if (l <= now && now <= r) {
c.push_back({0, r - now});
c.push_back({360 + l - now, 360});
return;
}
if (now <= l) {
c.push_back({l - now, r - now});
return;
}
if (now >= r) {
c.push_back({360 + l - now, 360 + r - now});
return;
}
};
for (int i = 0; i < n; i++) {
d64 dis = hypot<d64>(a[i].x - center.x, a[i].y - center.y);
double angle = atan2(a[i].y - center.y, a[i].x - center.x) * 180 / Pi;
if (angle < 0) {
angle += 360;
}
if (dis > d[0]) {
double angle2 = acos(d[0] / dis) * 180 / Pi;
push(180 - angle2, 180 + angle2, angle);
}
if (dis > d[1]) {
double angle2 = acos(d[1] / dis) * 180 / Pi;
push(0, angle2, angle);
push(360 - angle2, 360, angle);
}
}
sort(c.begin(), c.end());
double pre = 0;
for (auto [u, v] : c) {
if (u >= pre) {
ans += v - u;
pre = v;
} else if (v > pre) {
ans += v - pre;
pre = v;
}
}
cout << 360 - ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(15);
int tt = 1;
//cin >> tt;
for (int _ = 1; _ <= tt; _++) {
solve();
}
return 0;
}
A和cf一个题差不多
链接:
https://codeforces.com/contest/1430/problem/E
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
template <typename T>
class Fenwick {
public:
int n;
vector<T> tree;
Fenwick(const int &n) : n(n), tree(n) {}
inline void modify(int pos, T x) {
for ( ; pos <= n; pos += pos & -pos) {
tree[pos - 1] += x;
}
}
inline T get(int pos) {
T res = 0;
for ( ; pos > 0; pos -= pos & -pos) {
res += tree[pos - 1];
}
return res;
}
inline T sum(int l, int r) { // (l, r]
return get(r) - get(l);
}
};
constexpr int N = 26;
int cnt[N];
int half[N];
void solve() {
int n;
string s;
cin >> n >> s;
s = " " + s;
Fenwick<int> f(n);
vector<vector<int>> pos(26);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
pos[num].push_back(i);
}
i64 ans = 0;
for (int i = 1; i <= n; i++) {
int num = s[i] - 'a';
p[n - i + 1] = pos[num].back();
pos[num].pop_back();
}
for (int i = n; i >= 1; i--) {
ans += f.get(p[i]);
f.modify(p[i], 1);
}
cout << ans << '\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;
}
E
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
int n;
string s;
cin >> n >> s;
map<char, char> mp;
bool ok1 = 0, ok2 = 0, ok3 = 0;
string ans;
for (int i = 0; i < n; i++) {
mp[s[i]]++;
if (ok1 == 0 && mp[s[i]] == 5) {
ok1 = 1;
mp.clear();
for (int j = 0; j < 5; j++)
ans.push_back(s[i]);
} else if (ok2 == 0 && ok1 == 1 && mp[s[i]] == 7) {
ok2 = 1;mp.clear();
for (int j = 0; j < 7; j++)
ans.push_back(s[i]);
} else if (ok3 == 0 && ok1 == 1 && ok2 == 1 && mp[s[i]] == 5) {
ok3 = 1;
for (int j = 0; j < 5; j++)
ans.push_back(s[i]);
break;
}
}
if (ok3) {
cout << ans << '\n';
} else {
cout << "none" << '\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;
}
F
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
int n;
cin >> n;
if (n == 2 || n == 4) {
cout << -1 << '\n';
} else if (n % 2 == 0) {
cout << n / 2 << '\n';
for (int i = 1; i <= n / 2 - 1; i++) {
cout << i << ' ';
}
cout << n / 2 + 1;
cout << '\n';
} else {
cout << (n + 1) / 2 << '\n';
for (int i = 1; i <= n; i += 2) {
cout << i << ' ';
}
cout << '\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;
}
G
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
void solve() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int q;
cin >> q;
int I, J, l, r, p;
cin >> I >> J >> l >> r >> p;
int ans = 0;
for (int j = 0; j < m; j++) {
bool ok = 1;
for (int i = 0; i < n; i++) {
if (a[i][j] == '0') {
ok = 0;
break;
}
}
if (ok) {
ans++;
}
}
cout << ans << '\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;
}
H
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
constexpr int N = 1E5;
bool vis[2][N + 10];
void solve() {
int m, sy, ty;
cin >> m >> sy >> ty;
sy--;
ty--;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < m; j++) {
vis[i][j] = 0;
}
}
vector<vector<char>> a(2, vector<char>(m + 1));
for (int i = 0; i < 2; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
bool ok = 0;
function<void(int, int, int, int)> dfs = [&](int x, int y, int dx, int dy) {
if (ok) {
return;
}
if (x == 2 && y == ty) {
ok = 1;
return;
}
if (x > 1 || x < 0) {
return;
}
if (y > m - 1 || y < 0) {
return;
}
if (vis[x][y]) {
return;
}
vis[x][y] = 1;
if (a[x][y] == 'I') {
dfs(x + dx, y + dy, dx, dy);
} else if (a[x][y] == 'L') {
if (dx == 0 && dy == 1) {
dfs(x + 1, y, 1, 0);
dfs(x - 1, y, -1, 0);
} else if (dx == 1 && dy == 0) {
dfs(x, y + 1, 0, +1);
dfs(x, y - 1, 0, -1);
} else if (dx == 0 && dy == -1) {
dfs(x + 1, y, +1, 0);
dfs(x - 1, y, -1, 0);
} else if (dx == -1 && dy == 0) {
dfs(x, y + 1, 0, +1);
dfs(x, y - 1, 0, -1);
}
}
vis[x][y] = 0;
};
dfs(0, sy, 1, 0);
cout << (ok ? "YES" : "NO") << '\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;
}
I
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
//constexpr int M = 998244353;
//constexpr int M = 1000000007;
constexpr int N = 9;
int id[3][N][N];
int pos[3][N][N];
// 0 -> x
// 1 -> y
// 2 -> z
vector<array<int, 7>> a;
// [0]->time
// [1]->id
// [2]->in/out
// [3]->people
// [4]->x
// [5]->y
// [6]->z
void solve() {
int n, m, h;
cin >> n >> m >> h;
int k;
cin >> k;
for (int i = 1; i <= k; i++) {
int t, x, y, z;
cin >> t >> x >> y >> z;
if (t == 0) { // x
id[t][y][z] = i;
pos[t][y][z] = x;
} else if (t == 1) { // y
id[t][x][z] = i;
pos[t][x][z] = y;
} else { // z
id[t][x][y] = i;
pos[t][x][y] = z;
}
}
// (fx, fy, fz)
// ->
// (tx, fy, fz)
// ->
// (tx, ty, fz)
// ->
// (tx, ty, tz)
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
int t, fx, fy, fz, tx, ty, tz;
cin >> t >> fx >> fy >> fz >> tx >> ty >> tz;
auto get = [&](int people, int t0, int type, int A, int B, int &S, int T, int L) {
int POS = pos[type][A][B];
int ID = id[type][A][B];
int t1 = 0;
if (S >= POS) {
t1 = S - POS;
} else {
t1 = L + S - POS;
}
while (t1 < t0) {
t1 += L;
}
a.push_back({t1, ID, 1, people, fx, fy, fz});
int t2 = t1;
if (T > S) {
t2 += T - S;
} else {
t2 += L + T - S;
}
S = T;
a.push_back({t2, ID, 0, people, fx, fy, fz});
return t2 + 1;
};
if (fx != tx) {
t = get(i, t, 0, fy, fz, fx, tx, n);
}
if (fy != ty) {
t = get(i, t, 1, fx, fz, fy, ty, m);
}
if (fz != tz) {
t = get(i, t, 2, fx, fy, fz, tz, h);
}
}
sort(a.begin(), a.end());
int asz = a.size();
for (int i = 0; i < asz; i++) {
cout << "[" <<
a[i][0] << "s] Person " <<
a[i][3] << " " <<
(a[i][2] ? "IN" : "OUT") << " Elevator " <<
a[i][1] << " at (" <<
a[i][4] << ", " <<
a[i][5] << ", " <<
a[i][6] << ")\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;
}
标签:constexpr,河南省,++,long,cin,int,2022,using
From: https://www.cnblogs.com/kiddingma/p/16767328.html