M Cook Pancakes!
签到题,一共有
N
∗
2
N*2
N∗2个面,一次烤
K
K
K个面,一次最多烤
N
N
N个面(因为最多
N
N
N个烧饼一块烤),向上取整。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, k;
int a[N], b[N], f[N];
void work() {
cin >> n >> k;
if (k > n) {
k = n;
}
n *= 2;
cout << ceil(n * 1.0 / k);
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
work();
return 0;
}
G Xor Transformation
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define For(i, a, b) for (int i = a; i <= (b); ++i)
#define Rof(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
const int N = 1e5 + 5;
int n, m, k;
int a[N], b[N], f[N];
inline int input() {
int s = 0, f = 0, ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return f ? -s : s;
}
vector<int> ans;
void work() {
// cout << (1000000000000000000 ^ 152921504606846975 ^ 152921504606846976)
// << '\n';
a[0] = 1;
For(i, 1, 64) { a[i] = a[i - 1] * 2; }
// For(i, 1, 65) { cout << a[i] << "\n"; }
n = input(), m = input();
int x = n, l = 0;
while (x) {
l++, x /= 2;
}
// cout << l << "\n";
ans.push_back(a[l] - 1 - n);
ans.push_back(m ^ (a[l] - 1));
cout << ans.size() << '\n';
for (auto i : ans) {
cout << i << " ";
}
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
work();
return 0;
}
C Stone Game
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define For(i, a, b) for (int i = a; i <= (b); ++i)
#define Rof(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
const int N = 1e5 + 5;
int n, m, k;
int a[N], b[N], f[N];
inline int input() {
int s = 0, f = 0, ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return f ? -s : s;
}
void work() {
int a = input(), b = input(), c = input();
int mn = min(a, b);
a -= mn;
b -= mn;
int ans = mn * 2;
if (a == 0) {
if (b % 3 == 0) ans += b * 2;
if (b % 3 == 1) ans += b * 2 - 2;
if (b % 3 == 2) ans += b * 2;
}
if (b == 0) {
if (a % 3 == 0) ans += a;
if (a % 3 == 1) ans += a - 1;
if (a % 3 == 2) ans += a - 1;
}
cout << ans;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
work();
return 0;
}
D Fight against involution
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define For(i, a, b) for (int i = a; i <= (b); ++i)
#define Rof(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
const int N = 1e5 + 5;
int n, m, k;
int a[N], b[N], l[N], r[N];
inline int input() {
int s = 0, f = 0, ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return f ? -s : s;
}
struct node {
int l, r;
};
bool com(node x, node y) {
if (x.r == y.r) {
return x.l < y.l;
}
return x.r < y.r;
}
vector<node> ve;
void work() {
n = input();
For(i, 1, n) { ve.push_back({input(), input()}); }
ve.push_back({1, (int)1e9 + 5});
sort(all(ve), com);
int pre = -1, tot = 1, mx = 0, ppre = 0;
int ans = 0;
for (int i = 0; i <= n; i++) {
if (pre == -1) {
pre = ve[i].r;
continue;
}
// if (pre != ve[i].r) {
// ppre = mx;
// }
if (ve[i].r == pre) {
tot++;
mx = max(ve[i].l, mx);
} else {
mx = max(ve[i - 1].l, mx);
mx = max(mx, ppre);
ans += tot * mx;
// cout << ppre << "\n";
// cout << tot << '\n';
// cout << mx << '\n';
ppre = mx;
tot = 1;
mx = 0;
}
pre = ve[i].r;
}
cout << ans << '\n';
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
work();
return 0;
}