去哪儿 java后端笔试 9.7 前两道思路

三道编程题 : 1.滑冰体力选动作  2.RSA解密  3.德州扑克
只过了前两道,第三道模拟了一个多小时还是只过77%,想不出特殊用例来,求大家交流

1.滑冰
我直接暴力递归
used数组记录哪个动作用过了,防止重复
/**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 运动员可得到的最高分
     * @param energy int整型 运动员体力值
     * @param actions int整型二维数组 二维数组i为动作号 actions[i][0]为动作i+1消耗体力,actions[i][1]为动作i+1得分
     * @return int整型
     */
    public int maxScore (int energy, int[][] actions) {
        // write code here
        boolean[] used = new boolean[actions.length];
        process(energy, actions, used, 0);
        return max;
    }
    private int max = Integer.MIN_VALUE;

    public void process(int lastEnergy, int[][] actions, boolean[] used, int score) {
       if (lastEnergy < 0) {
           return;
       }

        max = Math.max(max, score);
        for (int i = 0; i < actions.length; i++) {
            if (used[i]) {
                continue;
            }
            if (actions[i][0] > lastEnergy) {
                continue;
            }
            used[i] = true;
            process(lastEnergy-actions[i][0], actions, used, score+actions[i][1]);
            used[i] = false;
        }
    }


2.解密
用了BigInteger直接模拟
/**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 解密
     * @param encryptedNumber int整型 待解密数字
     * @param decryption int整型 私钥参数D
     * @param number int整型 私钥参数N
     * @return int整型
     */
    public int Decrypt (int encryptedNumber, int decryption, int number) {
        // write code here
        BigInteger num = BigInteger.valueOf(1);
        for (int i = 0; i < decryption; i++) {
            num = num.multiply(BigInteger.valueOf(encryptedNumber));
        }
        num = num.mod(BigInteger.valueOf(number));

        return num.intValue();
    }

3.德州扑克
我是挨个牌型模拟,然后按照从大到小顺序判断符合条件就返回
没a
求教


#23届秋招笔面经#
全部评论
第一题01背包,第二题直接乘的同时取模就行,第三题就硬模拟不知哪错了过了80
点赞 回复 分享
发布于 2022-09-07 22:48 河南
第三题直接随机函数骗分,骗了45
点赞 回复 分享
发布于 2022-09-07 23:16 广西

相关推荐

02-15 09:23
已编辑
深圳技术大学 Java
德勤 后端 OC 实习140/天,转正税前7k
恶龙战士:不如码农烧烤
点赞 评论 收藏
分享
黑皮白袜臭脚体育生:简历统一按使用了什么技术实现了什么功能解决了什么问题或提升了什么性能指标来写会更好
点赞 评论 收藏
分享
黑皮白袜臭脚体育生:简历条例统一按使用了什么技术实现了什么功能解决了问题或提升了什么性能指标来写会好些,如使用布隆过滤器实现了判断短链接是否存在,大大提升了查询速度
点赞 评论 收藏
分享
评论
点赞
11
分享

创作者周榜

更多
牛客网
牛客企业服务