关注
献上我的代码,可惜就差一点时间就到了......
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失去的一切。5.5W
- 2... 这b学校一天天的不想着提高就业率就算了还拖累学生是吧?1.3W
- 3... 研一快手后端开发,一周速通,附一二面面经1.1W
- 4... 25校招 双非硕 拿下大厂🐧1.0W
- 5... 运气远大于努力?8167
- 6... 从竞赛到实习:我的成长之路与经验分享5401
- 7... 主包租房的经验总结!4083
- 8... 有谁遇到这情况?3973
- 9... 挚文集团-陌陌笔试202506063723
- 10... 小米一面3452
正在热议
更多
# 实习吐槽大会 #
45628次浏览 205人参与
# 产品实习,你更倾向大公司or小公司 #
150371次浏览 1931人参与
# 我的实习收获 #
37950次浏览 560人参与
# 得物求职进展汇总 #
96148次浏览 804人参与
# 晒一晒你的工位 #
88735次浏览 315人参与
# 硬件兄弟们 甩出你的华为奖状 #
103740次浏览 688人参与
# 现在还是0offer,延毕还是备考 #
1030292次浏览 7546人参与
# 大城市找工作会更容易吗 #
37984次浏览 332人参与
# 来聊聊你目前的求职进展 #
627042次浏览 6725人参与
# 如何看待offer收割机的行为 #
777058次浏览 6019人参与
# 工作中,努力重要还是选择重要? #
122677次浏览 1534人参与
# 互联网回暖,腾讯要招5000人! #
17075次浏览 557人参与
# 我的租房踩坑经历 #
39014次浏览 371人参与
# 26届秋招投递记录 #
5957次浏览 154人参与
# 产品每日一题 #
43222次浏览 560人参与
# 为什么国企只招应届生 #
172559次浏览 1140人参与
# 移动求职进展汇总 #
1796次浏览 19人参与
# 你觉得技术面多长时间合理? #
94305次浏览 684人参与
# 穿越回高考你还会选现在的专业吗 #
27199次浏览 302人参与
# 我和mentor的爱恨情仇 #
46104次浏览 288人参与