献上我的代码,可惜就差一点时间就到了...... 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; } } } }
点赞 评论

相关推荐

07-22 11:12
门头沟学院 Java
不是,我就随手投的怎么还真发面试啊
皮格吉:大厂特别快的——来自已经被共享中
点赞 评论 收藏
分享
06-13 17:33
门头沟学院 Java
顺序不记了,大致顺序是这样的,有的相同知识点写分开了1.基本数据类型2.基本数据类型和包装类型的区别3.==和equals区别4.ArrayList与LinkedList区别5.hashmap底层原理,put操作时会发生什么6.说出几种树型数据结构7.B树和B+树区别8.jvm加载类机制9.线程池核心参数10.创建线程池的几种方式11.callable与runnable区别12.线程池怎么回收线程13.redis三剑客14.布隆过滤器原理,不要背八股,说说真正使用时遇到了问题没有(我说没有,不知道该怎么回答了)15.堆的内存结构16.自己在写项目时有没有遇见过oom,如何处理,不要背八股,根据真实经验,我说不会17.redis死锁怎么办,watchdog机制如何发现是否锁过期18.如何避免redis红锁19.一个表性别与年龄如何加索引20.自己的项目的QPS怎么测的,有没有真正遇到大数量表21.说一说泛型22.springboot自动装配原理23.springmvc与springboot区别24.aop使用过嘛?动态代理与静态代理区别25.spring循环依赖怎么解决26.你说用过es,es如何分片,怎么存的数据,1000万条数据怎么写入库中27.你说用limit,那么在数据量大之后,如何优化28.rabbitmq如何批次发送,批量读取,答了延迟队列和线程池,都不对29.计网知不知道smtp协议,不知道写了对不对,完全听懵了30.springcloud知道嘛?只是了解反问1.做什么的?短信服务,信息量能到千万级2.对我的建议,基础不错,但是不要只背八股,多去实际开发中理解。面试官人不错,虽然没露脸,但是中间会引导我回答问题,不会的也只是说对我要求没那么高。面完问我在济宁生活有没有困难,最快什么时候到,让人事给我聊薪资了。下午人事打电话,问我27届的会不会跑路,还在想办法如何使我不跑路,不想扣我薪资等。之后我再联系吧,还挺想去的😭,我真不跑路哥😢附一张河科大幽默大专图,科大就是大专罢了
查看30道真题和解析
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务