360笔试



public class DNA {
    /**
     * 有一种特殊的DNA,仅仅由核酸A和T组成,长度为n,顺次连接
     *
     * 科学家有一种新的手段,可以改变这种DNA。每一次,科学家可以交换该DNA上两个核酸的位置,
     * 也可以将某个特定位置的核酸修改为另一种核酸。
     *
     * 现在有一个DNA,科学家希望将其改造成另一种DNA,希望你计算最少的操作次数。
     *
     *
     *
     * 输入描述
     * 输入包含两行,第一行为初始的DNA,第二行为目标DNA,保证长度相同。
     *
     * 输出描述
     * 输出最少的操作次数
     *
     *
     * 样例输入
     * ATTTAA
     * TTAATT
     * 样例输出
     * 3
     *
     * 提示
     * 对于100%的数据,DNA长度小于等于100000
     * 样例解释:
     * 1.首先修改第一个位置的核酸(从A修改为T)
     * 2.交换3和5位置的核酸
     * 3.交换4和6位置的核酸
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s1 = sc.nextLine().toCharArray();
        char[] s2 = sc.nextLine().toCharArray();
        ArrayDeque<Integer> a = new ArrayDeque<>();
        ArrayDeque<Integer> t = new ArrayDeque<>();
        for (int i = 0; i < s1.length; i++) {
            if (s1[i] != s2[i]) {
                if (s1[i] == 'A') {
                    a.offer(i);
                } else
                    t.offer(i);
            }
        }

        int res = 0;
        for (int i = 0; i < s1.length; i++) {
            if (s1[i] != s2[i]) {
                if (!a.isEmpty() && !t.isEmpty()) {
                    int y = t.poll();
                    int x = a.poll();
                    char tp = s1[x];
                    s1[x] = s1[y];
                    s1[y] = tp;
                }
                res++;
            }
        }
        System.out.println(res);

    }
}
public class 吃鸡组队 {
    /**
     * 最近一款吃鸡类型的游戏火爆全球。在组队模式下,你可以邀请自己的好友组建自己的小队,
     * 并选择是否填充(是否同意和非好友游玩),然后加入游戏。现在有A个单人队伍,B个双人队伍,C个三人队伍,D个四人队伍,
     * 并且全都同意填充,但已有的多人队伍的队员不能被拆开填充到其他队伍,请问最多能组成多少个四人队伍。
     * <p>
     * <p>
     * <p>
     * 输入描述
     * 第一行一个正整数T,表示数据组数。(1≤T≤100)
     * <p>
     * 接下来T行,每行四个非负整数,A,B,C,D。(0≤A, B, C, D≤150)
     * <p>
     * 输出描述
     * 共T行,每行输出一个队伍数。
     * <p>
     * <p>
     * 样例输入
     * 4
     * 1 2 3 4
     * 4 3 2 1
     * 2 2 2 1
     * 0 2 0 1
     * 样例输出
     * 6
     * 5
     * 4
     * 2
     */
    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int res = 0;
            res += d + Math.min(a, c);
            a = a - Math.min(a, c);
            if (a == 0)
                res += b >> 1;
            else {
                if (a / 2 >= b) {
                    a -= b << 1;
                    res += b;
                    res += a >> 2;
                } else {
                    b -= a >> 1;
                    res += a >> 1;
                    res += b >> 1;
                }
            }
            System.out.println(res);
        }

    }
}
public class 删数 {
    /**  这是一面手撕题
     * nums数组 输入x 原地修改nums,删掉nums中所有x
     * 输出新数组的长度
     */

    public int delete(int[] a, int x) {

        int l = a.length;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == x) {
                l = i;
                break;
            }
        }
        for (int i = l + 1; i < a.length; i++) {
            if (a[i] == x)
                continue;
            a[l++] = a[i];
        }

        return l;

    }
}



#360笔试#
全部评论
感谢分享!
点赞 回复
分享
发布于 2022-09-28 10:07 江苏

相关推荐

投票
byd惠州 研发岗 薪资(n-1)✖️1.36,利润奖不确定可能两月基本工资
点赞 评论 收藏
转发
点赞 16 评论
分享
牛客网
牛客企业服务