栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ccf 20210402

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ccf 20210402

暴力法(70):

import java.util.*;

public class Main {

    public static void main(String[] args){
        final int n,L,r,t;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        L = sc.nextInt();
        r = sc.nextInt();
        t = sc.nextInt();
        int[][] g = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = sc.nextInt();
            }
        }
        int cn=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int sum  = 0;
                for (int k = -r; k <=r; k++) {
                    for (int l = -r; l <= r; l++) {
                        if(i+k>=0 && i+k=0)
                            sum += g[i+k][j+l]-t;
                    }

                }
                if(sum<=0){
                    cn++;
                }
            }
        }
        System.out.println(cn);
    }
}

满分代码

import java.util.*;

public class Main {

    public static void main(String[] args){
        final int n,L,r,t;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        L = sc.nextInt();
        r = sc.nextInt();
        t = sc.nextInt();
        int[][] sumArr = new int[n+1][n+1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                sumArr[i+1][j+1] = sumArr[i+1][j] + sumArr[i][j+1] - sumArr[i][j] + sc.nextInt();

            }

        }
        int cn=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x1 = i - r +1 >=1? i-r+1:1;
                int y1 = j - r +1>=1? j-r+1:1;
                int x2 = i + r +1 <= n? i+r+1:n;
                int y2 = j + r + 1 <= n? j+r+1:n;
                int p = sumArr[x2][y2] - sumArr[x1-1][y2] - sumArr[x2][y1-1] +sumArr[x1-1][y1-1];
                if(p <= (x2-x1+1)*(y2-y1+1)*t)
                    cn++;
            }

        }
        System.out.println(cn);
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/732293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号