OPPO笔试
第一题过桥,就是最长连续0子序列。
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
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();
}
int juice = 0;
int curLength = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
// int cur = arr[i];
int j = i;
while (j < n && arr[j] == 0) {
j++;
}
curLength = j - i;
juice = Math.max(juice, curLength);
}
}
juice+=1;
System.out.println(juice);
}
}
第二题分割数组,每一段满足位相加小于k,求最小段数。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(); //长度
int k = in.nextInt(); //每段f函数值的上限
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
int curSum = 0;
int pieces = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > k) {
System.out.println(-1);
return;
}
curSum += arr[i];
if (curSum > k) {
curSum = arr[i];
pieces += 1;
} else {
continue;
}
}
pieces+=1;
System.out.println(pieces);
}
}
第三题1145子串,先算后缀和再求连续11子串。
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String str = in.nextLine();
long[] four_five = new long[n + 2];
int fiveCount = 0;
four_five[n + 1] = 0;
four_five[n] = 0;
for (int i = n - 1; i >= 0; i--) {
if (str.charAt(i) == '5') {
fiveCount += 1;
}
four_five[i] = four_five[i + 1];
if (str.charAt(i) == '4') {
four_five[i] += fiveCount;
}
}
long juice = 0;
for (int i = 0; i < n - 1; i++) {
if (str.charAt(i) == '1' && str.charAt(i + 1) == str.charAt(i)) {
juice += four_five[i + 2];
}
}
juice %= 1000000007;
System.out.println(juice);
}
}
挺不难的,但是挺多人全a也挂的

#牛客AI配图神器#
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
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();
}
int juice = 0;
int curLength = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
// int cur = arr[i];
int j = i;
while (j < n && arr[j] == 0) {
j++;
}
curLength = j - i;
juice = Math.max(juice, curLength);
}
}
juice+=1;
System.out.println(juice);
}
}
第二题分割数组,每一段满足位相加小于k,求最小段数。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(); //长度
int k = in.nextInt(); //每段f函数值的上限
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}
int curSum = 0;
int pieces = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > k) {
System.out.println(-1);
return;
}
curSum += arr[i];
if (curSum > k) {
curSum = arr[i];
pieces += 1;
} else {
continue;
}
}
pieces+=1;
System.out.println(pieces);
}
}
第三题1145子串,先算后缀和再求连续11子串。
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String str = in.nextLine();
long[] four_five = new long[n + 2];
int fiveCount = 0;
four_five[n + 1] = 0;
four_five[n] = 0;
for (int i = n - 1; i >= 0; i--) {
if (str.charAt(i) == '5') {
fiveCount += 1;
}
four_five[i] = four_five[i + 1];
if (str.charAt(i) == '4') {
four_five[i] += fiveCount;
}
}
long juice = 0;
for (int i = 0; i < n - 1; i++) {
if (str.charAt(i) == '1' && str.charAt(i + 1) == str.charAt(i)) {
juice += four_five[i + 2];
}
}
juice %= 1000000007;
System.out.println(juice);
}
}
挺不难的,但是挺多人全a也挂的
全部评论
相关推荐
查看12道真题和解析 点赞 评论 收藏
分享
点赞 评论 收藏
分享
03-19 17:53
武汉大学 算法工程师
暴杀流调参工作者:春招又试了一些岗位,现在投递很有意思,不仅要精心准备简历,投递官网还得把自己写的东西一条一条复制上去,阿里更是各个bu都有自己的官网,重复操作无数次,投完简历卡完学历了,又该写性格测评、能力测评,写完了又要写专业笔试,最近还有些公司搞了AI辅助编程笔试,有些还有AI面试,对着机器人话也听不明白录屏硬说,终于到了人工面试又要一二三四面,小组成员面主管面部门主管面hr面,次次都没出错机会,稍有不慎就是挂。
卡学历卡项目卡论文卡实习什么都卡,没有不卡的😂 点赞 评论 收藏
分享
