讯飞算法三题

public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.useDelimiter(" ");
        int n = in.nextInt();
        String arrStr = in.next();
        String[] arr = arrStr.split(" ");
        long[] powers = new long[arr.length];
        for (int i = 0; i < n; i++) {
            powers[i] = Long.parseLong(arr[i]);
        }
        int pos = 1;
        for (int i = 1; i < n; i++) {
            if(powers[i] == -1){
                pos = i;
                break;
            }
        }
        long left = powers[0];
        for (int i = pos - 1; i >= 1; --i) {
            if(powers[i] < left){
                left = powers[i];
            }
        }
        long right = powers[pos + 1];
        for (int i = pos + 1; i < n; ++i) {
            if(powers[i] < right){
                right = powers[i];
            }
        }
        System.out.println(left + right);
    }

public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.useDelimiter("\n");
        int n = in.nextInt();
        String arrStr = in.next();
        String[] arr = arrStr.split(" ");
        long[] arr1 = new long[arr.length];
        for (int i = 0; i < n; i++) {
            arr1[i] = Long.parseLong(arr[i]);
        }

        String arrStr2 = in.next();
        String[] arr_ = arrStr2.split(" ");
        long[] arr2 = new long[arr_.length];
        for (int i = 0; i < n; i++) {
            arr2[i] = Long.parseLong(arr_[i]);
        }

        long sum = 0;
        for (int i = 0; i < arr1.length; i++) {
            long top = (arr1[i] & (1 << 31));
            long bottom = (arr2[i] & (1 << 31));
            if(top != bottom){
                sum += Math.abs(arr1[i] + arr2[i]);
            }else{
                sum += Math.abs(arr1[i] - arr2[i]);
            }
        }
        System.out.print(sum);

    }
public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.useDelimiter("\n");
        int n = in.nextInt();
        String arrStr = in.next();
        String[] arr = arrStr.split(" ");
        long s = in.nextLong();

        Map<Long, Boolean> record = new HashMap<>();

        for (int i = 0; i < n; i++) {
            long item = Long.parseLong(arr[i]);
            if(item < s && !record.containsKey(s - item)){
                record.put(item, true);
            }
        }
        int maxUse = record.size() * 2;
        if(record.containsKey(s / 2)){
            System.out.print(s - maxUse);
        }else{
            System.out.print(s -1 - maxUse);
        }
    }
全部评论
选择题好多是考研题,很多已经忘了
点赞 回复 分享
发布于 2023-07-29 22:03 安徽

相关推荐

11-21 13:04
已编辑
门头沟学院 算法工程师
点赞 评论 收藏
分享
一个菜鸡罢了:哥们,感觉你的简历还是有点问题的,我提几点建议,看看能不能提供一点帮助 1. ”新余学院“别加粗,课程不清楚是否有必要写,感觉版面不如拿来写一下做过的事情,教育经历是你的弱势就尽量少写 2. “干部及社团经历”和“自我评价”删掉 3. 论文后面的“录用”和“小修”啥的都删掉,默认全录用,问了再说,反正小修毕业前肯定能发出来 4. 工作经验和研究成果没有体现你的个人贡献,着重包装一下个人贡献
点赞 评论 收藏
分享
评论
点赞
4
分享
牛客网
牛客企业服务