Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test1;
- import java.util.Arrays;
- public final class Main {
- static Pair[][] map = new Pair[7][5];
- static {
- map[0][0] = new Pair(0,-1); map[0][1] = new Pair(0,-1); map[0][2] = new Pair(1,-1); map[0][3] = new Pair(1,-1); map[0][4] = new Pair(2,-1);
- map[1][0] = new Pair(0,-1); map[1][1] = new Pair(0,-1); map[1][2] = new Pair(1,-1); map[1][3] = new Pair(0,-1); map[1][4] = new Pair(0,-1);
- map[2][0] = new Pair(2,-1); map[2][1] = new Pair(1,-1); map[2][2] = new Pair(1,-1); map[2][3] = new Pair(2,-1); map[2][4] = new Pair(0,-1);
- map[3][0] = new Pair(1,-1); map[3][1] = new Pair(1,-1); map[3][2] = new Pair(1,-1); map[3][3] = new Pair(0,-1); map[3][4] = new Pair(0,-1);
- map[4][0] = new Pair(2,-1); map[4][1] = new Pair(1,-1); map[4][2] = new Pair(1,-1); map[4][3] = new Pair(2,-1); map[4][4] = new Pair(1,-1);
- map[5][0] = new Pair(0,-1); map[5][1] = new Pair(0,-1); map[5][2] = new Pair(1,-1); map[5][3] = new Pair(1,-1); map[5][4] = new Pair(1,-1);
- map[6][0] = new Pair(0,-1); map[6][1] = new Pair(0,-1); map[6][2] = new Pair(2,-1); map[6][3] = new Pair(2,-1); map[6][4] = new Pair(2,-1);
- }
- static class Pair {
- public int type;
- public int color;
- public static int nextColor = 10;
- public Pair(int type, int color) {
- this.type = type;
- this.color = color;
- }
- public String showType() {
- return this.type+"";
- }
- public String showColor() {
- return this.color+"";
- }
- }
- void solve() {
- int[] proj = new int[map[0].length];
- Arrays.fill(proj, -1); int len = 0;
- for (int i = 0; i < map.length; i++) {
- boolean canDown = false;
- for (int j = 0; j < map[0].length; j++) {
- int type = map[i][j].type;
- if (type != 0) {
- if (j > 0 && map[i][j - 1].type == type) {
- if (proj[j] == -1) {
- map[i][j].color = map[i][j - 1].color;
- } else {
- map[i][j].color = map[i - 1][j].color;
- }
- len++;
- } else {
- map[i][j].color = ++Pair.nextColor;
- canDown = false;
- len = 0;
- }
- canDown = (i < (map.length - 1) && (map[i + 1][j].type == type)) ? true : false;
- if (canDown) {
- while (len >= 0) {
- proj[j - len] = map[i][j].color;
- len--;
- }
- } else {
- while (len >= 0) {
- proj[j - len] = -1;
- len--;
- }
- }
- }
- }
- }
- }
- Main() {
- printTypes(map);
- System.out.println();
- solve();
- printColor(map);
- }
- public static void main(String[] args) { new Main(); }
- void printTypes(Pair[][] array) {
- for (Pair[] row : array) {
- for (Pair somePair : row) {
- System.out.print(somePair.showType() + " ");
- }
- System.out.println();
- }
- }
- void printColor(Pair[][] array) {
- for (Pair[] row : array) {
- for (Pair somePair : row) {
- System.out.print(somePair.showColor() + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement