安排面试城市

今天有N个面试者需要面试,公司安排了两个面试的城市A和B,每一个面试者都有到A城市的开销costA和到B城市的开销costB。公司需要将面试者均分成两拨,使得total cost最小。

样例
输入: cost = [[5,4],[3,6],[1,8],[3,9]]
输出: 14
说明: 第一个和第二个人去B城市,剩下的去A城市
说明
题目要求去A的人数和去B的人数相等。

注意事项
N是偶数
2<=N<=1e5
答案确保在int范围内
1<=costA,costB <=1e6

//贪心的思想:a[0]-a[1]按照该差值进行排序
public int TotalCost(List<List<Integer>> cost) {
        // write your code here
              int n = cost.size();
        int totalB = 0;
        int[] diff = new int[n];
        for (int i = 0; i < n; i++) {
            totalB += cost[i][1];
            diff[i] = cost[i][0] - cost[i][1];
        }
        
        Arrays.sort(diff);
        int totalDiff = 0;
        for (int i = 0; i < n/2; i++) {
            totalDiff += diff[i];
        }
        
        return totalB + totalDiff;
    }

给定一个正整数,返回相应的列标题,如Excel表中所示。

样例
样例1

输入: 28
输出: “AB”
样例2

输入: 29
输出: “AC”
注意事项
1 -> A
2 -> B
3 -> C

26 -> Z
27 -> AA
28 -> AB

//进制转换问题;进展转换的话,n%我们想要转的进制,
然后n/=
  public String convertToTitle(int n) {
        // write your code here
     StringBuilder str = new StringBuilder();

        while (n > 0) {
            n--;
            str.append ( (char) ( (n % 26) + 'A'));
            n /= 26;
        }
        return str.reverse().toString();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值