网易笔试 100 100 100 60

网易笔试 100 100 100 60

  1. 数字之和S(n)小于x
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int t = in.nextInt();
            String res = "";
            int l = t / 9;
            if(t%9!=0)
                res += t % 9;
            for (int j = 0; j < l; j++) {
                res+=9;
            }
            System.out.println(res);
        }
    }

}
  1. 翻倍
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            long a = in.nextInt();
            long b = in.nextInt();
            long p = in.nextInt();
            long q = in.nextInt();
            int res = 0;
            while (a < b) {
                if (a + p < b) {
                    p = p * q;
                    res++;
                } else {
                    a += p;
                    res++;
                }
            }
            System.out.println(res);
        }
    }
}
  1. 最大连续子序列个数
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            int[] arr = new int[l];
            for (int j = 0; j < l; j++) {
                arr[j] = in.nextInt();
            }
            int t = 0, res = 0, max = 0;
            for (int j = 0; j < l; j++) {
                if (arr[j] >= t) {
                    res++;
                    t += arr[j];
                } else {
                    if (res > max) max = res;
                    res = 1;
                    t = arr[j];
                }
            }
            System.out.println(max);
        }
    }

}
  1. 逆序列的距离和
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        long res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if (arr[i] > arr[j]) {
                    res += j - i;
                }
            }
        }
        System.out.println(res);
    }
}
#网易##笔试题目#
全部评论
最后一题一开始就用归并调了一小时做出来了,人都调傻了
点赞 回复 分享
发布于 2019-09-21 17:01
第三题应该做错了。 1 5 1 3 9 12 25 这个数据集输出应该是4
点赞 回复 分享
发布于 2019-09-21 17:26
第四题代码,ac import java.util.Scanner; public class Netease4 { private static long count = 0; //辅助归并排序的数组 private static int[] helper; //用来存位置信息 private static int[] oldIndex; //类似于helper数组的问题辅助oldIndex数组的 private static int[] oldIndex2; /** * 跟归并求逆序对个数一样的思路,只是存储了每个数关于索引位置的信息来计算 * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] nums = new int[n]; helper = new int[n]; oldIndex = new int[n]; oldIndex2 = new int[n]; for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); oldIndex[i] = i; oldIndex2[i] = i; } mergeSort(nums, 0, n - 1); System.out.print(count); } private static void mergeSort(int[] nums, int low, int high) { if (high - low == 1) { if (nums[low] > nums[high]) { count++; swap(nums, low, high); swap(oldIndex, low, high); swap(oldIndex2, low, high); } return; } if (high == low) { return; } int mid = low + (high - low) / 2; mergeSort(nums, low, mid); mergeSort(nums, mid + 1, high); int index1 = mid, index2 = high, i = high; for (i = high; i >= low; i--) { if (index1 < low || index2 < mid + 1) { break; } if (nums[index1] <= nums[index2]) { helper[i] = nums[index2]; oldIndex2[i] = oldIndex[index2]; index2--; }else { helper[i] = nums[index1]; for (int j = mid + 1; j <= index2; j++) { count += oldIndex[j] - oldIndex[index1]; } oldIndex2[i] = oldIndex[index1]; index1--; } } //如果哪边没用完 if (index1 >= low) { while (index1 >= low) { helper[i] = nums[index1]; index1--; i--; } }else { while (index2 >= mid + 1) { helper[i] = nums[index2]; oldIndex2[i] = oldIndex[index2]; index2--; i--; } } for (int j = low; j <= high; j++) { nums[j] = helper[j]; oldIndex[j] = oldIndex2[j]; } } private static void swap(int[] nums, int a, int b) { int tmp = nums[a]; nums[a] = nums[b]; nums[b] = tmp; } } /* 5 2 3 4 2 5 5 3 1 4 2 5 5 3 2 4 1 5 9 3 1 4 2 5 2 6 7 8 */
点赞 回复 分享
发布于 2019-09-21 21:57
最后一题应该是用归并排序改一下来做,暴力60
点赞 回复 分享
发布于 2019-09-21 16:59
同样A3.6
点赞 回复 分享
发布于 2019-09-21 17:00
完了,我感觉,3.6烂大街了……面试又木有了
点赞 回复 分享
发布于 2019-09-21 17:01
都是3.6
点赞 回复 分享
发布于 2019-09-21 17:02
啥岗位,,,
点赞 回复 分享
发布于 2019-09-21 17:02
最后一题是该用归并……我本地写完扔到牛客就不对了……最后无奈还是暴力60,费力不讨好
点赞 回复 分享
发布于 2019-09-21 17:03
啥岗位,题目咋不一样……
点赞 回复 分享
发布于 2019-09-21 17:05
我服了,第二题第三题我算完把答案存起来,最后遍历输出的,结果通过率都是0
点赞 回复 分享
发布于 2019-09-21 17:06
第三题对吗?? 1 2 3 5 10
点赞 回复 分享
发布于 2019-09-21 17:31
第三题代码: import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int k = in.nextInt(); while(k-- != 0){ int n = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for(int i = 0; i < n ;i++){ list.add(in.nextInt()); } int left = 0, right = 1; int sum = list.get(0); int max = 1; while(right != n){ if(list.get(right) >= sum){ sum += list.get(right); right++; }else { while(list.get(right) < sum){ sum -= list.get(left); left++; } } max = Math.max(max,right-left); } System.out.println(max); } } } }
点赞 回复 分享
发布于 2019-09-21 17:41

相关推荐

爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
Hello_WordN:咱就是说,除了生命其他都是小事,希望面试官平安,希望各位平时也多注意安全
点赞 评论 收藏
分享
昨天 13:29
已编辑
湖南铁道职业技术学院 后端
小红书 后端选手 n*16*1.18+签字费期权
点赞 评论 收藏
分享
3 20 评论
分享
牛客网
牛客企业服务