📄 3447485_ac_297ms_2688k.java
字号:
import java.util.*;
public class Main {
private Scanner in;
private static int [][] place = new int [7][7];
private int [][] game;
static
{
place[0][2] = 1;place[0][3] = 2;place[0][4] = 3;
place[1][2] = 4;place[1][3] = 5;place[1][4] = 6;
place[2][0] = 7;place[2][1] = 8;place[2][2] = 9;place[2][3] = 10;place[2][4] = 11;place[2][5] = 12;place[2][6] = 13;
place[3][0] = 14;place[3][1] = 15;place[3][2] = 16;place[3][3] = 17;place[3][4] = 18;place[3][5] = 19;place[3][6] = 20;
place[4][0] = 21;place[4][1] = 22;place[4][2] = 23;place[4][3] = 24;place[4][4] = 25;place[4][5] = 26;place[4][6] = 27;
place[5][2] = 28;place[5][3] = 29;place[5][4] = 30;
place[6][2] = 31;place[6][3] = 32;place[6][4] = 33;
}
public static void main(String [] args) {
System.out.println("HI Q OUTPUT");
new Main().run();
System.out.println("END OF OUTPUT");
}
private void run() {
in = new Scanner (System.in);
int cas, num;
cas = in.nextInt();
while (cas-- > 0) {
game = new int [7][7];
while (true) {
num = in.nextInt();
if (num == 0) {
break;
}
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (place[i][j] == num) {
game[i][j] = 1;
}
}
}
}
while (play()) {
}
System.out.println(sum());
}
in.close();
}
private static int [][] mov = new int [4][];
static
{
mov[0] = new int [] {1, 0};
mov[1] = new int [] {0, 1};
mov[2] = new int [] {0, -1};
mov[3] = new int [] {-1, 0};
}
private boolean valid(int x, int y) {
return !(x < 0 || y < 0 || x > 6 || y > 6);
}
private boolean play() {
for (int i = 6; i >= 0; i--) {
for (int j = 6; j >= 0; j--) {
if (place[i][j] == 0 || game[i][j] == 1) {
continue;
}
for (int k = 0; k < 4; k++) {
int x1, y1, x2, y2;
x1 = i + mov[k][0];
y1 = j + mov[k][1];
if (!valid(x1, y1) || game[x1][y1] == 0)
{
continue;
}
x2 = x1 + mov[k][0];
y2 = y1 + mov[k][1];
if (!valid(x2, y2) || game[x2][y2] == 0)
{
continue;
}
game[i][j] = 1;
game[x1][y1] = game[x2][y2] = 0;
return true;
}
}
}
return false;
}
private int sum() {
int ret = 0;
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (place[i][j] != 0 && game[i][j] == 1) {
ret += place[i][j];
}
}
}
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -