zoukankan      html  css  js  c++  java
  • CCF 201912-2 回收站选址(100分)Java

    题目还没公布,先贴代码

    import java.util.Scanner;
    
    public class Main {
        
        public static void main(String[] args) {
            new Main().run();
        }
        
        public void run() {
            Scanner sc = new Scanner(System.in);
            
            int n = sc.nextInt();
            int[][] point = new int[n][2];
            int[] count = new int[5];
            sc.nextLine();
            for(int i = 0; i < n; i++) {
                String[] s = sc.nextLine().split(" ");
                point[i][0] = Integer.valueOf(s[0]);
                point[i][1] = Integer.valueOf(s[1]);
            }
            
            sort(point, n);
            
            for(int i = 0; i < n; i++) {
                int c = 0;
                int f = 0;
                for(int j = i-1; j >= 0 && point[j][0] >= point[i][0]-1; j--) {
                    if(point[i][0] == point[j][0] && point[i][1]-1 == point[j][1]) {
                        f++;
                    }
                    if(point[i][0] == point[j][0] && point[i][1]+1 == point[j][1]) {
                        f++;
                    }
                    if(point[i][0]-1 == point[j][0] && point[i][1] == point[j][1]) {
                        f++;
                    }
                    if(point[i][0]-1 == point[j][0] && point[i][1]-1 == point[j][1]) {
                        c++;
                    }
                    if(point[i][0]-1 == point[j][0] && point[i][1]+1 == point[j][1]) {
                        c++;
                    }
                }
                for(int j = i+1; j < n && point[j][0] <= point[i][0]+1; j++) {
                    if(point[i][0] == point[j][0] && point[i][1]-1 == point[j][1]) {
                        f++;
                    }
                    if(point[i][0] == point[j][0] && point[i][1]+1 == point[j][1]) {
                        f++;
                    }
                    if(point[i][0]+1 == point[j][0] && point[i][1] == point[j][1]) {
                        f++;
                    }
                    if(point[i][0]+1 == point[j][0] && point[i][1]-1 == point[j][1]) {
                        c++;
                    }
                    if(point[i][0]+1 == point[j][0] && point[i][1]+1 == point[j][1]) {
                        c++;
                    }
                }
                if(c >= 0 && f==4) {
                    count[c]++;
                }
            }
            for(int k = 0; k < 5; k++) {
                System.out.println(count[k]);
            }
            
            
        }
    
        private void sort(int[][] point, int n) {
            int[] temp = new int[2];
            for(int i = 0; i < n-1; i++) {
                for(int j = i + 1; j < n; j++) {
                    if(point[i][0] > point[j][0]) {
                        temp = point[i];
                        point[i] = point[j];
                        point[j] = temp;
                    }else if(point[i][0] == point[j][0] && point[i][1] > point[j][1]) {
                        temp = point[i];
                        point[i] = point[j];
                        point[j] = temp;
                    }
                }
            }
            
        }
    
    }
  • 相关阅读:
    mysql 查询当月天数
    mybatis <collection>标签 类型为string时无法获取重复数据错误
    eclipse 关闭validating
    YAGNI 声明
    tomcat 异常
    svn 用cmd命令行启动服务
    linux 命令
    windows10安装liux系统
    一带一路是个啥?
    串口通信协议
  • 原文地址:https://www.cnblogs.com/bruce1920/p/12051375.html
Copyright © 2011-2022 走看看