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;
                    }
                }
            }
            
        }
    
    }
  • 相关阅读:
    LeetCode 345. Reverse Vowels of a String 题解
    LeetCode 344. Reverse String 题解
    LeetCode 27. Remove Element 题解
    LeetCode 61. Rotate List 题解
    LeetCode 19.Remove Nth Node From End of List 题解
    Android耗电量
    Android 使用adb查看和修改电池信息
    Android AOP AspectJ 插桩
    Flask相关用法
    Monkey日志信息的11种Event percentage
  • 原文地址:https://www.cnblogs.com/bruce1920/p/12051375.html
Copyright © 2011-2022 走看看