学无止境吖:谢谢,简历已投
投递字节跳动等公司10个岗位 >
0 点赞 评论 收藏
分享
80 100 80 0能有面试机会吗, 大家都说说自己ac了多少吧哈哈 第四题bfs没做出来,提交之后发现忘记每次遍历都初始化了,但估计也会超时,菜啊
檐之:发一下前三题100%的代码吧……最后一题快写出来了……但是估计还要半个小时才能调试出来 1. 起床 package a;
import java.util.Scanner;
public class Main {
static class Clock implements Comparable<Clock>{
int hour, minute;
public Clock(int hour, int minute) {
this.hour = hour;
this.minute = minute;
}
@Override
public int compareTo(Clock o) {
if (this.hour != o.hour) {
return this.hour - o.hour;
}
return this.minute - o.minute;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Clock[] clocks = new Clock[n];
for (int i = 0; i < n; i++) {
int hour = scanner.nextInt();
int minute = scanner.nextInt();
clocks[i] = new Clock(hour, minute);
}
int route = scanner.nextInt();
Clock lesson = new Clock(scanner.nextInt(), scanner.nextInt());
while (lesson.minute < route) {
lesson.hour -= 1;
route -= 60;
}
lesson.minute -= route;
Clock latest = clocks[0];
for (int i = 0; i < clocks.length; i++) {
if (clocks[i].compareTo(lesson) <= 0 && clocks[i].compareTo(latest) >= 0) {
latest = clocks[i];
}
}
System.out.println(latest.hour + " " + latest.minute);
}
}
2. 解密 package b;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
String secret = scanner.next();
char[] result = new char[n];
result[0] = secret.charAt(0);
for (int i = 1; i < k; i++) {
result[i] = xor(secret.charAt(i), secret.charAt(i - 1));
}
for (int i = k; i < n; i++) {
result[i] = xor(xor(secret.charAt(i), secret.charAt(i - 1)), result[i - k]);
}
System.out.println(new String(result));
}
private static char xor(char a, char b) {
return a == b ? '0' : '1';
}
}
3. 分钱 package c;
import java.util.*;
public class Main {
public static final int MIN_MONEY = 100;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
// 年份对应的座位号
TreeMap<Integer, List<Integer>> map = new TreeMap<>();
int[] people = new int[n];
for (int i = 0; i < n; i++) {
people[i] = scanner.nextInt();
if (!map.containsKey(people[i])) {
map.put(people[i], new ArrayList<>());
}
map.get(people[i]).add(i);
}
int[] money = new int[n];
int[] tmp = new int[n];
while (!map.isEmpty()) {
int lowestKey = map.firstKey();
for (int i : map.get(lowestKey)) {
if (i == 0) {
tmp[i] = money[i + 1] + 100;
} else if (i == n - 1) {
tmp[i] = money[i - 1] + 100;
} else {
tmp[i] = Math.max(money[i - 1], money[i + 1]) + 100;
}
}
for (int i : map.get(lowestKey)) {
money[i] = tmp[i];
}
map.remove(lowestKey);
}
int sum = 0;
for (int i : money) {
sum += i;
}
System.out.println(sum);
}
}
前三题都还可以……一个小时就做完了,但是最后一题想贪全最后没有做完,还是太菜了
投递字节跳动等公司10个岗位 >
0 点赞 评论 收藏
分享
0 点赞 评论 收藏
分享
关注他的用户也关注了: