[CCF CSP 的刷题记录]

[CCF CSP 的刷题记录],第1张

CCF CSP 的刷题记录

文章目录
  • CCF CSP 的刷题记录
  • 2021年09月 赛题
    • 第一题 202109-1 数组推导
    • 第二题 202109-2 非零段划分
    • 第三题 202109-3 脉冲神经网络
    • 第四题 收集卡牌
    • 第五题 箱根山岳险天下

  • 开始之前的一些说明
    • 只是刷题记录
    • 所有题目的提交链接,都需要登入到CCF CSP,因为都是模拟考试,需要账号登录的

辅助代码的参考

#pragma GCC POSITION goto

#pragma GCC optimize(2)

// #pragma GCC optimize(3,"Ofast","inline")

#define DO_PRAGMA(x) _Pragma (#x)
#define TODO(x) DO_PRAGMA(message ("TODO - " #x))

#include 
#include 
#include 
#include 

int main(int argc, char const *argv[]) {
#ifndef ONLINE_DEBUG
    freopen("input.data", "r", stdin);
    freopen("output.data", "w", stdout);
#endif
    char *str = (char*)malloc(2 * sizeof(char)); memset(str, 0, sizeof(char)); 
    // char str[32]; memset(str, 0, sizeof(char));
    printf("the size of str: %ld\n", sizeof(str));
    scanf("%2[^abcd]", str); scanf("%*c");
    printf("str = %s\n", str);
    free(str);
    return 0;
}

2021年09月 赛题 第一题 202109-1 数组推导

题目提交链接 这题是真的简单 😄

#pragma GCC POSITION goto

#pragma GCC optimize(2)

// #pragma GCC optimize(3,"Ofast","inline")

#include 
#include 

int main(int argc, const char **argv) {
#ifndef ONLINE_DEBUG
    freopen("input.data", "r", stdin);
    freopen("output.data", "w", stdout);
#endif
	int n = 0,  max = 0, min = 0, i = 0, b[100]; 
	memset(b, 0, sizeof(int));
  	scanf("%d", &n);scanf("%*c");
	for(i=0; i<n; ++i) { scanf("%d", &b[i]);scanf("%*c"); }
	max = min = b[0];
	for(i=1; i<n; ++i) {
		max += b[i]; if(b[i]>b[i-1]) min += b[i];
	}
	printf("%d\n%d", max, min);
	return 0;
}
第二题 202109-2 非零段划分

题目提交链接 这题挺复杂的,要那分的话 😢

#pragma GCC POSITION goto

#pragma GCC optimize(2)

// #pragma GCC optimize(3,"Ofast","inline")
#include 
#include 

#define N (int)5e5+5
#define M (int)1e4+1
#define _max(a,b) ((a) > (b) ? (a): (b))

int main(int argc, const char **argv) {
#ifndef ONLINE_DEBUG
    freopen("input.data", "r", stdin);
    freopen("output.data", "w", stdout);
#endif
    int n = 0, sum = 0, phrase = 0, i = 0, a[N], cnt[N]; // 整数个数,段数
    scanf("%d", &n); scanf("%*c");
    for(i = 1; i <= n; i++) {
        scanf("%d", &a[i]); scanf("%*c");
        if(a[i] > a[i-1]) { //差分,p取a[i-1]+1~a[i]的非零段数量加一
            cnt[a[i-1]+1]++; cnt[a[i]+1]--;
        }
    }
 
    for(i = 1; i < M; i++) {
        sum += cnt[i]; phrase = _max(phrase, sum);
    }
 
    printf("%d\n", phrase);
    return 0;
}
第三题 202109-3 脉冲神经网络
#pragma GCC POSITION goto

#pragma GCC optimize(2)

// #pragma GCC optimize(3,"Ofast","inline")

#define DO_PRAGMA(x) _Pragma (#x)
#define TODO(x) DO_PRAGMA(message ("TODO - " #x))

#include 
#include 

#define N  2010
#define INF 1e8
#define _max(a, b) ({(a) > (b) ? (a): (b);})
#define _min(a, b) ({(a) > (b) ? (b): (a);})
#define _rand() ({ _next = _next * 1103515245 + 12345; (unsigned)(_next/65536) % 32768;})
#define add(a,b,c,d) do {e[idx] = (b), W[idx] = (c), D[idx] = (d), ne[idx] = h[(a)], h[(a)] = idx++ ;} while(0)

double I[1<<10][N>>1];

int main(int argc, const char **argv) {
TODO(There is still some problems when I upload the test. - HJR)
#ifndef ONLINE_DEBUG
    freopen("input.data", "r", stdin);
    freopen("output.data", "w", stdout);
#endif
    static unsigned long _next = 1;
    int n = 0, s = 0, p = 0, T = 0, i = 0, j = 0, k = 0, idx = 0, h[N], e[N], D[N], ne[N], r[N], cnt[N];
    double dt = 0.0, W[N], v[N], u[N], a[N], b[N], c[N], d[N];
    memset(h, -1, sizeof(h));
    scanf("%d%d%d%d%lf", &n, &s, &p, &T,&dt);scanf("%*c");
    for (i = 0; i < n;) {
        int rn; scanf("%d", &rn);scanf("%*c");
        double vv, uu, aa, bb, cc, dd;
        scanf("%lf%lf%lf%lf%lf%lf", &vv, &uu, &aa, &bb, &cc, &dd);scanf("%*c");
        for (j = 0; j < rn; j++, i++ ) {
            v[i] = vv, u[i] = uu, a[i] = aa, b[i] = bb, c[i] = cc, d[i] = dd;
        }
    }

    for (i = n; i < n + p; i++ ) {scanf("%d", &r[i]);scanf("%*c");}

    int mod = 0;
    while (s--) {
        int a = 0, b = 0, d = 0;
        double c;
        scanf("%d%d%lf%d", &a, &b, &c, &d);scanf("%*c");
        add(a, b, c, d);
        mod = _max(mod, d + 1);
    }

    for (i = 0; i < T; i++ ) {
        int t = i % mod;
        for (j = n; j < n + p; j++ )
            if (r[j] > _rand()) {
                for (k = h[j]; ~k; k = ne[k]) {
                    int x = e[k];
                    I[(t + D[k]) % mod][x] += W[k];
                }
            }

        for (j = 0; j < n; j++ ) {
            double vv = v[j], uu = u[j];
            v[j] = vv + dt * (0.04 * vv * vv + 5 * vv + 140 - uu) + I[t][j];
            u[j] = uu + dt * a[j] * (b[j] * vv - uu);

            if (v[j] >= 30) {
                for (k = h[j]; ~k; k = ne[k]) {
                    int x = e[k];
                    I[(t + D[k]) % mod][x] += W[k];
                }
                cnt[j]++ ;
                v[j] = c[j], u[j] += d[j];
            }
        }

        memset(I[t], 0, sizeof(I[t]));
    }

    double minv = INF, maxv = -INF;
    int minc = (int)INF, maxc = (int)-INF;

    for (i = 0; i < n; i++ ) {
        minv = _min(minv, v[i]);
        maxv = _max(maxv, v[i]);
        minc = _min(minc, cnt[i]);
        maxc = _max(maxc, cnt[i]);
    }

    printf("%.3lf %.3lf\n", minv, maxv); printf("%d %d\n", minc, maxc);
    return 0;
}
第四题 收集卡牌 第五题 箱根山岳险天下

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/562853.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-02
下一篇 2022-04-02

发表评论

登录后才能评论

评论列表(0条)

保存