爱奇艺笔试
由于爱奇艺发送的邮件中说明了不让随意传播试题内容,所以我只说一下非常粗略的题型吧。
第一部分
选择题:python,Java基础语法,基础知识。操作系统,网络等基础知识
第二部分
第一题
SQL题非常简单,我的答案:
select demand_id, count(id) as count from Task group by demand_id having count > 1;
第二题
一个数组,一个滑动窗口,求额,,,算了不多说了,给一下我的代码,只过了66%,想看完整题目的私信我吧唉,,
我的错误,是k,k不一定是3,但是我只初始化了3个值,以下是我的错误代码。
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); String[] split = s.split(","); String[] last = split[split.length - 1].split(":"); int[] arr = new int[split.length]; int k = Integer.valueOf(last[1]); for (int i = 0; i < split.length-1; i++) { arr[i] = Integer.valueOf(split[i]); } arr[split.length - 1] = Integer.valueOf(last[0]); maxP(arr, k); } private static void maxP(int[] arr, int k) { double maxRes = 0; double sum = arr[0] + arr[1] + arr[2]; double prejun = sum / k; double curjun = 0; for (int i = 3; i < arr.length; i++) { sum = sum + arr[i] - arr[i-k]; curjun = sum / k; if ((curjun - prejun) / prejun > maxRes) { maxRes = (curjun - prejun) / prejun; } prejun = curjun; } maxRes *= 100; DecimalFormat df = new DecimalFormat("#.00"); String res = df.format(maxRes); System.out.println(res+"%"); }
2021/8/3更新,根据评论区大家的指导重新写了maxP方法 :smile:
private static void maxP(int[] arr, int k) { double maxRes = 0; double sum = 0; // 先初始化前k个 for (int i = 0; i < k; i++) { sum += arr[i]; } double preSum = sum; double curSum = 0; // 从第k个开始,遍历到结尾,计算平均增幅取最大放到maxRes // 评论区说可以不用算均值,意思是:当前均值 = 当前和/k 前一个均值 = 前一个和/k // 平均值增幅 = (当前均值 - 前一个均值)/前一个均值 = (当前和 - 前一个和)/前一个和 for (int i = k; i < arr.length; i++) { sum = sum + arr[i] - arr[i-k]; curSum = sum; maxRes = Math.max(maxRes, (curSum - preSum) / preSum); preSum = curSum; } maxRes *= 100; DecimalFormat df = new DecimalFormat("#.00"); String res = df.format(maxRes); System.out.println(res+"%"); }
第三题
这题提示说是贪心,但我觉我我写的没啥问题,只过了50%,详细我不说了,想要题目的私信我吧,,
public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); String[] strings = s.split(","); int[] rains = new int[strings.length]; rains[0]=Integer.valueOf(strings[0].charAt(1)-'0'); for (int i = 1; i < strings.length-1; i++) { rains[i] = Integer.valueOf(strings[i]); } rains[strings.length - 1] = Integer.valueOf(strings[strings.length - 1].charAt(0) - '0'); // System.out.println(Arrays.toString(rains)); int[] ans = new int[rains.length]; process(rains, ans); System.out.println(Arrays.toString(ans)); } private static void process(int[] rains, int[] ans) { HashSet<Integer> rained = new HashSet<>(); for (int i = 0; i < rains.length; i++) { if (rains[i] != 0) { if (rained.contains(rains[i])) { ans = new int[rains.length]; return; } ans[i] = -1; rained.add(rains[i]); } else { for (int j = i+1; j < rains.length; j++) { if (rains[j] != 0 && rained.contains(rains[j])) { ans[i] = rains[j]; rained.remove(rains[j]); break; } } } } }
2021/8/3 更新process方法,新添加了一个判断
private static void process(int[] rains, int[] ans) { Set<Integer> rained = new HashSet<>(); for (int i = 0; i < rains.length; i++) { if (rains[i] != 0) { if (rained.contains(rains[i])) { ans = new int[0]; return; } ans[i] = -1; rained.add(rains[i]); } else { // 遍历一边发现最近能够能够引发洪水的一个湖泊,抽干他! for (int j = i+1; j < rains.length; j++) { if (rains[j] != 0 && rained.contains(rains[j])) { ans[i] = rains[j]; rained.remove(rains[j]); break; } } // 如果遍历了一遍,发现没有那种能犯洪水的湖泊了,那就随便从有水的湖泊中抽一个 if (ans[i] == 0 && !rained.isEmpty()) { ans[i] = rained.iterator().next(); rained.remove(ans[i]); } } } }
第四题
哇,最后一题是搞多线程的,而且是异步的,需要我们实现三个方法,来翻译给的字符串,
public static class Job<V> { public void newTask(Callable<V> runnable) { //待实现 } public void execute(Executor executor) { //待实现 } public List<V> get() throws InterruptedException { //待实现 } }
真不会做呀,详情私信我吧,,,,,
就这样,宝友们,可不兴说我题目不完整,爱奇艺发的邮件说不让瞎传播哈。
有全ac的大佬,求个完美答案!!!!!!!!!!!!!!
全部评论
(22) 回帖