关注
献上我的代码,可惜就差一点时间就到了......
import java.util.Scanner;
public class WanMeiShiJie {
public static final int EMPTY = Integer.MAX_VALUE;
public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
public static final int YELLOW = 3;
public static final int PURPLE = 4;
public static final int[][] p = {
{RED,RED,BLUE,BLUE,GREEN,YELLOW,BLUE,YELLOW,RED,PURPLE},
{GREEN,GREEN,GREEN,BLUE,RED,PURPLE,RED,YELLOW,YELLOW,BLUE},
{BLUE,RED,RED,YELLOW,YELLOW,PURPLE,BLUE,GREEN,GREEN,BLUE},
{YELLOW,RED,BLUE,YELLOW,BLUE,RED,PURPLE,GREEN,GREEN,RED},
{YELLOW,RED,BLUE,BLUE,PURPLE,GREEN,PURPLE,RED,YELLOW,BLUE},
{PURPLE,YELLOW,RED,RED,YELLOW,RED,PURPLE,YELLOW,RED,RED},
{YELLOW,YELLOW,GREEN,PURPLE,GREEN,RED,BLUE,YELLOW,BLUE,GREEN},
{RED,YELLOW,BLUE,BLUE,YELLOW,GREEN,PURPLE,RED,BLUE,GREEN},
{GREEN,GREEN,YELLOW,YELLOW,RED,RED,PURPLE,BLUE,BLUE,GREEN},
{PURPLE,BLUE,RED,RED,PURPLE,YELLOW,BLUE,RED,RED,GREEN}};
public static void main(String[] args) {
int numR, numG, numB, numY, numP;
numR = numG = numB = numY = numP = 0;
for(int i = 0; i < p.length; i++){
for(int j = 0; j < p[0].length; j++){
switch (p[i][j]) {
case RED:
numR++;
break;
case GREEN:
numG++;
break;
case BLUE:
numB++;
break;
case YELLOW:
numY++;
break;
case PURPLE:
numP++;
break;
default:
break;
}
}
}
System.out.println("inital :" + numR + " " + numG + " " + numB + " " + numY + " " + numP );
Scanner cin = new Scanner(System.in);
while(cin.hasNextLine()){
String str = cin.nextLine();
String[] nums = str.split(" ");
for(String num : nums){
int click = Integer.parseInt(num);
int x = click / 10;
int y = (click - 1) % 10;
int color = p[x][y];
int delete = countContinue(p, x, y);
switch (color) {
case RED:
numR -= delete;
break;
case GREEN:
numG -= delete;
break;
case BLUE:
numB -= delete;
break;
case YELLOW:
numY -= delete;
break;
case PURPLE:
numP -= delete;
break;
default:
break;
}
for(int i = 0; i < p[0].length; i++){
if(p[p.length - 1][i] == EMPTY)
moveCols(p, i);
}
}
System.out.println(numR + " " + numG + " " + numB + " " + numY + " " + numP );
}
}
public static int countContinue(int[][] p, int x, int y){
int color = p[x][y];
int start = x;
int count = 1;
while(start + 1 < p.length && p[start + 1][y] == color){
start ++;
}
int idx = start;
while(idx - 1 >= 0 && p[idx - 1][y] == color){
count ++;
idx--;
}
dispearCol(p, y, start, count);
int beforeY = y - 1;
int afterY = y + 1;
while(beforeY >= 0 && p[x][beforeY] == color){
dispearCol(p, beforeY, x, 1);
beforeY--;
count++;
}
while(afterY < p[0].length && p[x][afterY] == color){
dispearCol(p, afterY, x, 1);
afterY ++;
count++;
}
return count;
}
public static void dispearCol(int[][] p, int col, int start, int count){
int j = start;
for(int i = start - count; i >= 0; i--, j--){
p[j][col] = p[i][col];
}
for(; j >=0; j--)
p[j][col] = EMPTY;
}
public static void moveCols(int[][] p, int col){
for(int i = col, j = i + 1; j < p[0].length; i++, j++){
for(int k = 0; k < p.length; k++){
p[k][i] = p[k][j];
}
}
if(col < p[0].length - 1){
for(int k = 0; k < p.length; k++){
p[k][p[0].length - 1] = EMPTY;
}
}
}
}
查看原帖
点赞 评论
相关推荐
06-04 18:03
河南工程学院 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 工作中哪个瞬间让你想离职 #
32118次浏览 238人参与
# 我对___祛魅了 #
2816次浏览 34人参与
# 中兴秋招 #
183144次浏览 2043人参与
# 和同事相处最忌讳的是__ #
2773次浏览 31人参与
# 打工人的精神状态 #
62843次浏览 1049人参与
# 如何快速融入团队? #
1217次浏览 25人参与
# 机械人,你被简历秒挂的企业有哪些? #
45741次浏览 295人参与
# 职场常用语录大全 #
5086次浏览 41人参与
# 机械人,秋招第一次笔试的企业是哪家? #
42162次浏览 335人参与
# 在职场上,你最讨厌什么样的同事 #
17681次浏览 174人参与
# 担心入职之后被发现很菜怎么办 #
142449次浏览 822人参与
# 哪些公司校招卡第一学历 #
83822次浏览 363人参与
# 职场人,说说你的烦心事 #
12646次浏览 106人参与
# 软开人,秋招你打算投哪些公司呢 #
109878次浏览 991人参与
# 你觉得找工作该拿大厂还是小厂练手 #
196284次浏览 1752人参与
# 如果重来一次你还会读研吗 #
180871次浏览 1816人参与
# 秋招想进国企该如何准备 #
77557次浏览 427人参与
# 机械人晒出你的简历 #
87416次浏览 715人参与
# 工作一周年分享 #
32465次浏览 193人参与
# 金融财会交流会 #
112999次浏览 386人参与
# 找工作中的意难平 #
784930次浏览 6125人参与