关注
献上我的代码,可惜就差一点时间就到了......
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;
}
}
}
}
查看原帖
点赞 评论
相关推荐
牛客热帖
更多
- 1... 6月18日,我将站上法庭,正式起诉美团。我送出的每一单快件,都是我人生碎片的一部分。我会一直前进,拿回在海外SaaS失去的一切。3.8W
- 2... 这b学校一天天的不想着提高就业率就算了还拖累学生是吧?1.2W
- 3... 25校招 双非硕 拿下大厂🐧7044
- 4... 运气远大于努力?4858
- 5... 从竞赛到实习:我的成长之路与经验分享4083
- 6... 有谁遇到这情况?3405
- 7... 小米一面2683
- 8... 《客户端从入门到ssp》2583
- 9... 25届0offer2270
- 10... 上海银行 修改入职协议 不还本科毕业证学位证双证原件 😂2201
正在热议
更多
# 实习吐槽大会 #
46901次浏览 214人参与
# 产品实习,你更倾向大公司or小公司 #
150469次浏览 1931人参与
# 我的实习收获 #
38574次浏览 561人参与
# 得物求职进展汇总 #
96233次浏览 804人参与
# 晒一晒你的工位 #
88987次浏览 315人参与
# 硬件兄弟们 甩出你的华为奖状 #
103790次浏览 689人参与
# 现在还是0offer,延毕还是备考 #
1030462次浏览 7547人参与
# 产品每日一题 #
43261次浏览 560人参与
# 如何看待offer收割机的行为 #
777193次浏览 6020人参与
# 大城市找工作会更容易吗 #
38051次浏览 332人参与
# 工作中,努力重要还是选择重要? #
122795次浏览 1536人参与
# 来聊聊你目前的求职进展 #
627120次浏览 6725人参与
# 投格力的你,拿到offer了吗? #
82131次浏览 571人参与
# 互联网回暖,腾讯要招5000人! #
17087次浏览 557人参与
# 我的租房踩坑经历 #
39917次浏览 382人参与
# 26届秋招投递记录 #
6031次浏览 155人参与
# 为什么国企只招应届生 #
172604次浏览 1140人参与
# 提前批过来人的忠告 #
103150次浏览 1123人参与
# 移动求职进展汇总 #
1808次浏览 19人参与
# 我和mentor的爱恨情仇 #
46277次浏览 289人参与