首页 > 其他分享 >CSP 2020

CSP 2020

时间:2022-09-28 15:34:56浏览次数:38  
标签:int void long day 2020 mod CSP define

涩图

普及 优秀的拆分 (橙)

没手也行

点击查看代码
#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());
}

标签:int,void,long,day,2020,mod,CSP,define
From: https://www.cnblogs.com/eafoo/p/16737267.html

相关文章

  • csp模拟13[排序,Xorum, 有趣的区间问题,无聊的卡牌问题]
    排序对于这个题,它真的很妙,我们可以先考虑一下(如果\(a\)是排列)暴力怎么打。考虑两个数,他们互为逆序对,如果交换它们两个,如何让影响降到最小?那就是在他俩交换之后,他......
  • csp模拟12[开挂,叁仟柒佰万, 超级加倍, 欢乐豆 ]
    今日总结:卢本伟nb,我卢本伟没有开挂T1开挂人类智慧题....可我不够智慧我们考虑最终答案的和一定是一个定值,因为如果我将最终的序列再加一个一的话,他还是合法的,但......
  • [CSP-S2019] Emiya 家今天的饭
    P5664CSP-S2019Emiya家今天的饭容斥原理+DP答案=没有限制3的答案-∑某一列不满足性质3的答案,记号:行表示方案,纵表示食材第2类:不满足性质3的只有一种列(必须>k/2......
  • CSP-S模拟13
    全nm构造题,我爆零了T1.排序我读错题了……以为这是个普通的冒泡排序。因为需要用到所有的逆序对,所以每一次操作只能减少一个逆序对。考虑从小到大归位,我们按从大到小的顺......
  • CSP 2022 备战 时间复杂度
    如果我们要对一个程序进行评级,可以通过什么?最显著的,自然是通过测试点评价其次,就是通过时间复杂度与空间复杂度来评级了由于空间一般是十分充足的,UKE的报错情况少之又少......
  • CSP-S模拟8
    全是\(JOI\)的题……为什么不做本民族的题(恼)T1.选举原以为是一道神奇贪心,所以写了\(O(n)\)的转移,但是发现\(n<=500\),这……都不用跑都知道假了。好吧,是一道dp——我们把n......
  • CSP-S模拟13排序 Xorum 有趣的区间问题 无聊的卡牌问题
    T1【构造+规律】:给你一个排列,要你求逆序对数量,把原序列的逆序对位置当成交换,进行任意排列使得最后序列升序。(n<=1000)一:排列的实质是id[i]=i的一一对应,问题互相转化会更简......
  • CSP202203_3
    CSP202203_3目录CSP202203_3题目思路Code题目计算资源调度器思路直接模拟,画个大致的分析图即可理清题目要求。一个区上有多个节点,一个应用有多个任务。一个任务只占......
  • CSP-S模拟13
    又是模拟退役的一天A.排序死因:输出没有让前面小于后面通过找规律发现交换两个数值相邻的一定可以原因是这样保证每次操作只减少一个逆序对code#include<bits/std......
  • CSP模拟13
    套路题不会。考虑重修一下。T1经过考后的采访,joke3579、gtm1514、Chen_jr、Muel_imj四个人考场上写的Checker都拍过了然后都挂了零。实际上从前往后扫,只要交换每个位置......