「csp模拟」模拟测试11

总结

T1的约瑟夫问题很早很早就讲过了,但没有记住线性解决约瑟夫问题的方法,T2模拟题没有花太多时间去打,还是模拟能力太差,T3暴力50分,由于把阶乘打到了多测里面,每次跑了一遍,挂了35分,T4暴力70分,稳稳的拿住了。

One

  • 约瑟夫问题,对于每一轮都重新编号,最终剩下的只有一号,然后根据本轮中的一号一定是上一轮中死的那一号+1,一次递推到最初状态。
//cinput
/*
2
2
3
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 1;
inline int read() {
    int k = 0, f = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) k = k * 10 + ch - '0';
    return k * f;
}
int main() {
#ifndef debug
    freopen("one.in", "r", stdin);
    freopen("one.out", "w", stdout);
#endif
    int T = read();
    while (T--) {
        int n = read(), ans = 0;
        for (register int i = 2; i <= n; i ++) {
            ans = (ans + (n - i + 1)) % i;
        }       
        printf ("%d\n", ans + 1);
    }
    return 0;
}

砖块

  • 纯模拟,没写出来,没啥可讲的。
//cinput
/*
3
2
ENEESESSESWWWN
5
WNSEWNSEWNSEWWSEN
3
NNEEESESWWNWWWWWSSEEEEENNE
*/
#include <bits/stdc++.h>
using namespace std;
inline int read() {
    int k = 0, f = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) k = k * 10 + ch - '0';
    return k * f;
}
const int maxn = 201;
int cnt[maxn][maxn], ansx[maxn], ansy[maxn];
struct block {
    int x1, y1, x2, y2, h, maxcnt;
    block(int a, int b, int c, int d, int e) : x1(a), y1(b), x2(c), y2(d), h(e) {
        memset(cnt, 0, sizeof(cnt)), maxcnt = 0;
    }
    void next(char opt) {
        int lastx1 = x1, lastx2 = x2, lasty1 = y1, lasty2 = y2;
        if (opt == 'N') y1 = y2, y2 += h, h = lasty2 - lasty1;
        else if (opt == 'S') y2 = y1, y1 -= h, h = lasty2 - lasty1;
        else if (opt == 'W') x2 = x1, x1 -= h, h = lastx2 - lastx1;
        else x1 = x2, x2 += h, h = lastx2 - lastx1;
        for (int i = x1; i < x2; i++) {
            for (int j = y1; j < y2; j++) {
                maxcnt = std::max(maxcnt, ++cnt[i + 100][j + 100]);
            }
        }
    }
};
int main() {
#ifdef local
//  freopen("in", "r", stdin);
#else
    freopen("block.in", "r", stdin), freopen("block.out", "w", stdout);
#endif
    int T = read();
    while (T--) {
        int h = read();
        char s[maxn]; scanf("%s", s + 1);
        block b = block(0, 0, 1, 1, h);
        cnt[100][100] = 1;
        for (int i = 1; s[i]; i++) b.next(s[i]);
        int tot = 0;
        for (int i = b.x1; i < b.x2; i++) {
            for (int j = b.y1; j < b.y2; j++) {
                ansx[++tot] = i, ansy[tot] = j;
            }
        }
        for (int i = 1; i <= tot; i++) printf("%d ", ansx[i]); puts("");
        for (int i = 1; i <= tot; i++) printf("%d ", ansy[i]); puts("");
        printf("%d\n", b.maxcnt);
    }
    return 0;
}

数字

  • 这题正解太难,暴力可得50分,考场上花了好长时间测试这道题,最后加多测时把线性阶乘放在了while中,导致每次都跑一遍。。。傻了傻了。。。
//50分
//cinput
/*
5
1 1
5 1
10 2
233 3
12346 3
*/
#include <bits/stdc++.h>
using namespace std;
inline int read() {
    int k = 0, f = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) k = k * 10 + ch - '0';
    return k * f;
}
const int maxn = 1e7 + 10;
int jc[maxn];
signed main() {
#ifdef local
    //freopen("in", "r", stdin);
#else
    freopen("num.in", "r", stdin);
    freopen("num.out", "w", stdout);
#endif
    signed T = read();
    register unsigned long long cur = 1, tmp;
    jc[0] = 1;
    for (register int i = 1; i <= 1e7; i++) {
        cur *= i;
        while (cur % 10 == 0) cur /= 10;
        cur %= 10000000;
        jc[i] = cur;
    }
    while (T--) {
        register int n = read(), k = read();
        unsigned cur = jc[n];
        if (k == 1) printf("%d\n", cur % 10);
        else if (k == 2) printf("%d%d\n",(cur/10)%10, cur%10);
        else printf("%d%d%d\n",(cur/100)%10,(cur/10)%10, cur%10);
    }
}

甜圈

  • 这个70分暴力直接写,我不知道考试时为什么要开一个vector,后来感觉要卡常就改了basic_string,这个数据结构在题库中跑的特快,一上评测机就慢的不行,题库中200ms+的点跑了1200ms+。。。挂了好多分啊。。。

  • 正解线段树,显然,哈希判断

//cinput
/*
5 3
5
2 3 1
1 3 2
4 5 1
2 4 3
3 5 2
*/
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
inline int read() {
    int k = 0, f = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) k = k * 10 + ch - '0';
    return k * f;
}
const int maxn = 200010 * 4, base = 13;
struct tree { int l, r, val, mlaz, plaz, siz; } t[maxn];
#define tl t[rt].l
#define tr t[rt].r
#define ls (rt << 1)
#define rs (rt << 1 | 1)
void build(int rt, int l, int r) {
    t[rt].l = l, t[rt].r = r, t[rt].siz = r - l + 1;
    t[rt].mlaz = 1;
    t[rt].plaz = 0;
    if (l == r) { return; }
    int mid = (l + r) >> 1;
    build(ls, l, mid);
    build(rs, mid + 1, r);
}
void pushdown(int rt) {
    if (tl == tr) return;
    t[ls].val = t[rt].mlaz * t[ls].val + t[rt].plaz * t[ls].siz;
    t[ls].mlaz = t[ls].mlaz * t[rt].mlaz;
    t[ls].plaz = t[ls].plaz * t[rt].mlaz + t[rt].plaz;
    t[rs].val = t[rt].mlaz * t[rs].val + t[rt].plaz * t[rs].siz;
    t[rs].mlaz = t[rs].mlaz * t[rt].mlaz;
    t[rs].plaz = t[rs].plaz * t[rt].mlaz + t[rt].plaz;
    t[rt].mlaz = 1;
    t[rt].plaz = 0;
    // cout << t[rt].val << " " << t[rt].mlaz << " " << t[rt].plaz << endl;
}
void pushup(int rt) {
    t[rt].val = t[ls].val + t[rs].val;
}
void modify(int rt, int l, int r, int val1, int val2) {
    if (l <= tl && tr <= r) {
        t[rt].val = t[rt].siz * val1 + t[rt].val * val2;
        t[rt].mlaz = t[rt].mlaz * val2;
        t[rt].plaz = t[rt].plaz * val2 + val1;
        return;
    }
    pushdown(rt);
    int mid = (tl + tr) >> 1;
    if (l <= mid) modify(ls, l, r, val1, val2);
    if (r > mid) modify(rs, l, r, val1, val2);
    pushup(rt);
}
int tot = 0;
int ask(int rt) {
    if (tl == tr) {
        // cout << t[rt].val << endl;
        if (t[rt].val == tot) return 1;
        else return 0;
    }
    pushdown(rt);
    int mid = (tl + tr) >> 1;
    return ask(ls) + ask(rs);

}
signed main() {
#ifndef local
    freopen("deco.in", "r", stdin), freopen("deco.out", "w", stdout);
#endif
    int n = read(), k = read();
    build(1, 1, n);
    for (int i = 1; i <= k; i++) tot = tot * base + i;
    int T = read();
    while (T--) {
        int l = read(), r = read(), x = read();
        modify(1, l, r, x, base);
    }
    printf("%lld\n", ask(1));
}
posted @ 2020-10-11 11:56  hyskr  阅读(112)  评论(0编辑  收藏  举报