村代码

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class acw528 {
    static Scanner sc = new Scanner(System.in);

    static int t;
    public static void main(String[] args) {
        t = sc.nextInt();
        for (int i = 1; i <= t; i ++ ) {
            solved();
        }
    }

    static PIII[] points = new PIII[t];
    static int n, h, r;
    public static void solved() {
        n = sc.nextInt();
        h = sc.nextInt();
        r = sc.nextInt();

        points = new PIII[n];
        List<PIII> in = new ArrayList<>();
        List<PIII> out = new ArrayList<>();
        for (int i = 0; i < n; i ++ ) {
            int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
            points[i] = new PIII(x, y, z);
            if (points[i].z - r <= 0) in.add(points[i]);
            if (points[i].z + r >= h) out.add(points[i]);
        }

    }

    public static boolean check(PIII point1, PIII point2) {
        long dist = (long) (point1.x - point2.x) * (point1.x - point2.x) + (long) (point1.y - point2.y)
                * (point1.y - point2.y) + (long) (point1.z - point2.z) * (point1.z - point2.z);
        return dist <= (long) r * r;
    }

    static class PIII {
        int x, y, z;
        public PIII(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }
}

import java.util.HashMap;
import java.util.Scanner;

// 如何存储 ?
// 如何利用哈希表 ?

public class acw1402 {
static int w, h;
static char[][] g;
static HashMap<String, Character> hashMap;

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    w = sc.nextInt(); h = sc.nextInt(); // 注意h和w
    g = new char[h][w];
    vis = new boolean[h][w];
    hashMap = new HashMap<>();

    for (int i = 0; i < h; i ++ ) {
        String s = sc.next();
        for (int j = 0; j < w; j ++ ) {
            g[i][j] = s.charAt(j);
        }
    }

    int cnt = 0;
    for (int i = 0; i < h; i ++ ) {
        for (int j = 0; j < w; j ++ ) {
            if (vis[i][j] || g[i][j] == '0') continue;
            sb = new StringBuilder("ST"); // 采用空格分割+方向的方式进行存储
            floodFill(i, j);
            String t = sb.toString();
            if (hashMap.containsKey(t)) continue;

            System.out.println("[now x and y] : " + "[" + i + ", " + j + "]");
            cnt ++ ;
            hashMap.put(t, (char) ('a' + (cnt - 1)));
        }
    }

    System.out.println(hashMap);
    System.out.println(hashMap.values());
}

static boolean[][] vis;
final static int[] dx = new int[] {-1, 0, 1, 0, -1, -1, 1, 1};
final static int[] dy = new int[] {0, 1, 0, -1, -1, 1, -1, 1};
static StringBuilder sb;
public static void floodFill(int x, int y) {
    vis[x][y] = true;
    for (int i = 0; i < 8; i ++ ) {
        int a = x + dx[i], b = y + dy[i];
        if (a < 0 || a >= h || b < 0 || b >= w) continue;
        if (vis[a][b]) continue;
        if (g[a][b] == '0') continue;
        sb.append(" ").append(dx[i]).append(dy[i]);
        floodFill(a, b);
    }
}

}

/*
a b c d e f g (7个)
23
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000
*/


posted @ 2024-03-21 09:49  李菜菜想获奖  阅读(23)  评论(0)    收藏  举报