普及 优秀的拆分 (橙)
没手也行
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (register int x = l; x <= r; ++x)
#define fio(x, r, l) for (register int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 30 + 3, maxm = 13;
int ans[maxn], tot;
signed main() {
int x = read();
if (x & 1) puts("-1"), exit(0);
int res = 1;
while (x) {
if (x & 1) ans[++tot] = res;
res <<= 1, x >>= 1;
}
fio(i, tot, 1) printf("%lld ", ans[i]);
putchar('\n');
}
普及 直播获奖 (橙)
成绩不超过 600?桶排。
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (register int x = l; x <= r; ++x)
#define fio(x, r, l) for (register int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 30 + 3, maxm = 600 + 3;
int a[maxm];
signed main() {
int n = read(), w = read();
fop(i, 1, n) {
++a[read()];
int x = max(1ll, i * w / 100);
fio(j, 600, 0) {
x -= a[j];
if (x <= 0) { printf("%lld ", j); break; }
}
}
putchar('\n');
}
普及 方格取数 (黄)
简单 DP
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (register int x = l; x <= r; ++x)
#define fio(x, r, l) for (register int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 1e3 + 3, maxm = 600 + 3;
int f[maxn][maxn][3];
int a[maxn][maxn];
signed main() {
int n = read(), m = read();
fop(i, 1, n) fop(j, 1, m) a[i][j] = read();
memset(f, 0xc0, sizeof f);
f[1][1][0] = f[1][1][1] = f[1][1][2] = a[1][1];
fop(i, 2, n) f[i][1][1] = f[i - 1][1][1] + a[i][1];
fop(j, 2, m) {
fop(i, 1, n) {
f[i][j][0] = max({f[i][j - 1][1], f[i][j - 1][0], f[i][j - 1][2]}) + a[i][j];
if (i >= 2) f[i][j][1] = max(f[i - 1][j][0], f[i - 1][j][1]) + a[i][j];
}
fio(i, n - 1, 1) f[i][j][2] = max(f[i + 1][j][0], f[i + 1][j][2]) + a[i][j];
}
printf("%lld\n", max({f[n][m][0], f[n][m][1], f[n][m][2]}));
}
普及 表达式 (绿)
很有意思的题
建表达式树,统计改每个值对最终答案的影响
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (register int x = l; x <= r; ++x)
#define fio(x, r, l) for (register int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 1e6 + 3, maxm = 600 + 3;
struct data { int id, v; } stk[maxn];
char s[maxn];
int a[maxn], e[maxn], top, tot;
int pos[maxn], f[maxn];
signed main() {
fgets(s + 1, maxn - 1, stdin);
int n = read();
fop(i, 1, n) a[i] = read();
int len = strlen(s + 1);
fop(i, 1, len) {
if (s[i] == 'x') {
++i; int x = 0;
while (isdigit(s[i])) x = (x << 1) + (x << 3) + (s[i] ^ 48), ++i;
e[++tot] = x, pos[x] = tot;
}
else if (s[i] == '&') e[++tot] = -1;
else if (s[i] == '|') e[++tot] = -2;
else if (s[i] == '!') e[++tot] = -3;
}
fop(i, 1, tot) {
if (e[i] > 0) stk[++top] = (data) { i, a[e[i]] };
else if (e[i] == -3) {
data tx = stk[top];
stk[top] = (data) { i, !tx.v };
f[tx.id] = i;
}
else if (e[i] == -2) {
data tx = stk[top], ty = stk[top - 1];
--top, stk[top] = (data) { i, tx.v | ty.v };
if (!ty.v) f[tx.id] = i;
if (!tx.v) f[ty.id] = i;
}
else if (e[i] == -1) {
data tx = stk[top], ty = stk[top - 1];
--top, stk[top] = (data) { i, tx.v & ty.v };
if (ty.v) f[tx.id] = i;
if (tx.v) f[ty.id] = i;
}
}
int res = stk[top].v;
int q = read();
while (q--) {
int x = read(), y;
for (y = pos[x]; f[y]; y = f[y]);
printf("%lld\n", y == tot ? !res : res);
}
}
提高 儒略日 (绿)
曾经的大模拟,现在打起来还是很简单的
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (register int x = l; x <= r; ++x)
#define fio(x, r, l) for (register int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 1e6 + 3, maxm = 600 + 3;
const int by = -4712, bm = 1; // the 0th year is the replacement of the -1th year
const int ce = 1721424; // 1.1.1
const int rnm1582 = 2298884; // 1582.1.1
const int rnm1583 = 2299239; // 1583.1.1
const int bc4 = 365 * 4 + 1;
const int ce400 = 365 * 400 + 100 - 3;
int y400[ce400 + 5], m400[ce400 + 5], d400[ce400 + 5];
bool Leap(int y) {
if (y < 1582 && y % 4 == 0) return 1;
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) return 1;
return 0;
}
int Day(int y) { return y == 1582 ? 355 : 365 + Leap(y); }
int Day(int y, int m) {
if (m == 2) return 28 + Leap(y);
if (y == 1582 && m == 10) return 21;
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) return 31;
return 30;
}
void Init() {
int y = 1583, m = 1, d = 0;
fop(i, 0, ce400 - 1) {
++d;
if (d == Day(y, m) + 1) d = 1, ++m;
if (m == 13) m = 1, ++y;
y400[i] = y - 1583, m400[i] = m, d400[i] = d;
}
}
void Work(int day) {
int y = by, m = bm;
if (day < ce) {
// warning: in the original problem, -1, -5, -9 is leap year, not -4, -8
y += day / bc4 * 4, day %= bc4;
while (day >= Day(y)) day -= Day(y), ++y;
while (day >= Day(y, m)) day -= Day(y, m), ++m;
printf("%lld %lld %lld BC\n", day + 1, m, -y + 1);
return;
}
if (day >= rnm1582 && day < rnm1583) {
day -= rnm1582, y = 1582;
while (day >= Day(y, m)) day -= Day(y, m), ++m;
if (m == 10 && day > 3) printf("%lld %lld %lld\n", day + 10 + 1, m, y);
else printf("%lld %lld %lld\n", day + 1, m, y);
return;
}
if (day < rnm1582) {
day -= ce, y = 1;
y += day / bc4 * 4, day %= bc4;
while (day >= Day(y)) day -= Day(y), ++y;
while (day >= Day(y, m)) day -= Day(y, m), ++m;
printf("%lld %lld %lld\n", day + 1, m, y);
return;
}
day -= rnm1583, y = 1583;
y += day / ce400 * 400, day %= ce400;
printf("%lld %lld %lld\n", d400[day], m400[day], y400[day] + y);
}
signed main() {
Init();
int q = read();
while (q--) Work(read());
}