• 第二十二次CCF计算机软件能力认证


    1、灰度直方图

    ACwing 3411

    #include 
    #include 
    using namespace std;
    
    const int N = 510;
    
    int n, m, Len;
    int h[N];
    
    int main() {
        cin >> n >> m >> Len;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                int x; cin >> x;
                h[x]++;
            }
        for (int i = 0; i < Len; i++) cout << h[i] << " ";
        puts("");
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2、邻域均值

    ACwing3412

    #include 
    #include 
    using namespace std;
    
    const int N = 610;
    
    int n, L, r, t;
    int s[N][N];
    
    int get_sum(int x1, int y1, int x2, int y2) {
        return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
    }
    
    int get_cnt(int x1, int y1, int x2, int y2) {
        return (x2 - x1 + 1) * (y2 - y1 + 1);
    }
    
    int main() {
        cin >> n >> L >> r >> t;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) {
                int x; cin >> x;
                s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + x;;
            }
        int res = 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) {
                int x1 = max(1, i - r), y1 = max(1, j - r);
                int x2 = min(n, i + r), y2 = min(n, j + r);
                if (get_sum(x1, y1, x2, y2) <= t * get_cnt(x1, y1, x2, y2)) res++;
            }
        cout << res << endl;
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    3、DHCP服务器

    ACwing 3413

    4、校门外的树 (DP)

    ACwing 3414

    状态表示
    集合 f [ i ] f[i] f[i]:区间 a 0 ∼ a i a_0 \sim a_i a0ai 上所有选法的集合
    属性:数量

    集合划分
    根据最后一个区间左端点 j ( j ∈ [ 0 , i − 1 ] ) j (j \in [0, i - 1]) j(j[0,i1]) 的位置,将集合划分为 i i i

    状态计算
    记区间 [ a j , a i ] [a_j, a_i] [aj,ai] 之间的距离为 d d d,将区间等分,其每段距离记为 k k k。由于必须至少要划分为两段,则 k k k 应该取除 d d d 本身之外的所有 d d d 的约数,且选定的划分点不能与前面已经选择的点重合,则在区间 [ a j , a i ] [a_j, a_i] [aj,ai] 上的所有方案为 ∑ k \sum k k
    f [ i ] = f [ i ] + f [ j ] × ∑ k f[i] = f[i] + f[j] \times \sum k f[i]=f[i]+f[j]×k

    #include 
    #include 
    #include 
    #include 
    using namespace std;
    
    typedef long long LL;
    const int N = 1010, M = 100010, MOD = 1e9 + 7;
    
    int n;
    int a[N];
    int f[N];
    vector<int> q[M];
    bool st[M];
    
    int main() {
        for (int i = 1; i < M; i++) // 每个数的所有约数
            for (int j = i * 2; j < M; j += i)
                q[j].push_back(i);
    
        scanf("%d", &n);
        for (int i = 0; i < n; i++) scanf("%d", a + i);
        f[0] = 1;
        for (int i = 1; i < n; i++) {
            memset(st, 0, sizeof st);
            for (int j = i - 1; j >= 0; j--) {
                int d = a[i] - a[j], cnt = 0;
                for (int k: q[d]) if (!st[k]) cnt++, st[k] = true;
                st[d] = true;
                f[i] = (f[i] + (LL) f[j] * cnt) % MOD;
            }
        }
        printf("%d\n", f[n - 1]);
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
  • 相关阅读:
    C# 45. ref和out的区别
    【ElasticSearch】HTTP调用API
    Servlet(Cookie和Session)
    【java计算机毕设】高校奖学金管理系统 java springmvc vue mysql 送文档+ppt
    风控ML[16] | 风控建模中怎么做拒绝推断
    循序渐进搞懂 TCP 三次握手核心
    武汉星起航给想做亚马逊精细化铺货模式的卖家分享一些技巧
    [Web安全 网络安全]-学习视频分享汇总(持续更新中)
    利用python学习如何处理需要登录的网站
    六、TCP实现聊天
  • 原文地址:https://blog.csdn.net/qq_34696503/article/details/126417152