微众9.13

1.微众银行9.13

这一题设计知识点:Arrays.sort排序及Comparator自定义排序

Java Arrays.sort排序及Comparator自定义排序_cpyy103的博客-CSDN博客

 相关题目力扣179.

package ACM_Exercise;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author Halu
 * @create 2022-09-15 9:38
 */
public class Weizhong01 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String input1 = in.nextLine();
        String[] nums = input1.split(" ");
        String resStr = concatMaxNums(nums);
        BigInteger res = new BigInteger(resStr);//特别大的数字,应该用BigInteger
        System.out.println(res);
    }

    public static String concatMaxNums(String[] nums){
        Arrays.sort(nums,(a, b) -> (b + a).compareTo(a + b));
        if (nums[0].charAt(0) == '0') return "0";
        return String.join("", nums);
    }
}

2. 移位游戏

微众银行笔试9.13_笔经面经_牛客网

思路:先求a和b之间的倍数,再求这个倍数是多少个2,再将2的幂数除以3,2和1求得乘除8,4和2的次数

import java.util.Scanner;

public class _wz2 {
    public static long log(long n)
    {
        long count = 0;
        if(n == 1)
            return 0;

        while(n > 1)
        {
            n = n>>1;	//右移 -> 除以2的1次方
            count++;
        }
        return count;
    }

    public static long Count(long a, long b,long ans){
        if ((a>b ? a%b:b%a) != 0) return -1;
        long res = a>b ? a/b:b/a;   //求倍率
        long count = 0;
        if(res==1) return 0;
        if((res&1)==1) return -1;
        else
            res = log(res); //倍率换算成多少个2

//        统计变换次数
        count += (res/3);
        res %= 3;
        count += (res/2);
        res %= 2;
        count += res;

        return count;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int i = 0; i<T; i++){
            long a = sc.nextLong();
            long b = sc.nextLong();
            System.out.println(Count(a,b,0));
        }
    }
}


3. 上升子序列

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值