网易2019测试开发笔试编程第一题(小易俄罗斯方块)

题目描述

小易有一个古老的游戏机,上面有着经典的游戏俄罗斯方块。因为它比较古老,所以规则和一般的俄罗斯方块不同。荧幕上一共有n列,每次都会有一个1x 1的方块随机落下,在同一列中,后落下的方块会叠在先前的方块之上,当一整行方块都被占满时,这一行会被消去,并得到1分。有一天,小易又开了一一局游戏,当玩到第m个方块落下时他觉得太无聊就关掉了,小易希望你告诉他这局游戏他获得的分数。
输入描述:
第一行两个数n, m
第二行m个数,C1,C2,….Cm,Ci表示第i个方块落在第几列
其中 1 <= n,m <= 1000,1 <= Ci <= n
输出描述
小易这句游戏获得的分数

示例1
输入:
3 9
1 1 2 2 2 3 1 2 3
输出:
2
package test;


import java.util.Scanner;


public class Game{

    //计算非零个数
    public static int cou(int m,int[] num){
        int s = 0;
        for(int i = 0;i< m;i++){
            if(num[i] != 0){
                s = s+1;
            }
        }
        return s;
    }
    //计算分数
    public static void countScore(int n,int m,int[] num){
        int score = 0;
        do {
            int count = 1;
            for (int i = 0; i < m; i++) {
                if (num[i] == count && count <=(n+1)) {
                    count = count + 1;
                    num[i] = 0;
                }
            }
            if(count-1 == n){
                score += (count-1)/n;
            }

        }while(cou(m,num)>=n);

        System.out.println(score);

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String s = sc.nextLine();
        String inputString = sc.nextLine();
        String stringArray[] = inputString.split(" ");
        int num[] = new int[m];
        for (int i = 0; i < m; i++) {
            num[i] = Integer.parseInt(stringArray[i]);
        }
        countScore(n, m, num);
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值