Untitled
unknown
plain_text
2 years ago
3.3 kB
1
Indexable
Never
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.awt.Point; import java.util.Arrays; import java.util.Comparator; public class PlayersFinder{ public static int area=0; public static int minx=99; public static int maxx=0; public static int miny=99; public static int maxy=0; public static int hight =0; public static int width =0; public static void check (char[][] board,boolean[][] checked,int y, int x, int i,int j, char t){ // x,y are like the math axis //checks if the point is valid if (i<0 || j<0 || i>=y || j>=x || board[i][j] != t || checked[i][j]){ return; } area++; checked[i][j]= true ; check(board,checked,y,x,i+1,j,t); //up check(board,checked,y,x,i,j+1,t); //right check(board,checked,y,x,i-1,j,t); //down check(board,checked,y,x,i,j-1,t); //left if(2*(i+1)<miny) miny=2*(i+1); if(2*(i+1)>maxy) maxy=2*(i+1); if(2*(j+1)<minx) minx=2*(j+1); if(2*(j+1)>maxx) maxx=2*(j+1); } public static void main(String[] args) { Scanner s = new Scanner(System.in); String Dim = s.nextLine(); String[] parts = Dim.split(","); hight = Integer.parseInt(parts[0].trim()); width = Integer.parseInt(parts[1].trim()); char[][] board =new char [hight][width]; for (int i = 0; i < hight; i++) { String row = s.nextLine(); for (int j = 0; j < width; j++) { board[i][j] = row.charAt(j); } } int tid = s.nextInt(); int Area = s.nextInt(); s.close(); boolean[][] checked = new boolean [hight][width]; Point[] p = new Point[90]; int numPoints = 0; for (int k = 0; k < hight; k++) { for (int l = 0; l < width; l++) { if (board[k][l] < 64) { check(board, checked, hight, width, k, l, (char) (tid + '0')); if (area * 4 >= Area) { p[numPoints] = new Point(((minx + maxx) / 2) - 1, ((miny + maxy) / 2) - 1); numPoints++; } area = 0; minx = 99; maxx = 0; miny = 99; maxy = 0; } } } Point[] pp = new Point[numPoints]; for (int m = 0; m < numPoints; m++) { pp[m]=p[m]; } Arrays.sort(pp, new Comparator<Point>() { public int compare(Point a, Point b) { int xComp = Integer.compare(a.x, b.x); if(xComp == 0) return Integer.compare(a.y, b.y); else return xComp; } }); System.out.print("["); for (int m = 0; m < numPoints; m++) { System.out.print("(" + pp[m].x + ", " + pp[m].y + ")"); if (m < numPoints - 1) { System.out.print(", "); } } System.out.print("]"); } }