关注
发一下前三题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);
}
}
前三题都还可以……一个小时就做完了,但是最后一题想贪全最后没有做完,还是太菜了
查看原帖
点赞 1
相关推荐
牛客热帖
正在热议
# 25届秋招总结 #
320354次浏览 2965人参与
# 上班苦还是上学苦呢? #
68613次浏览 590人参与
# 阿里云管培生offer #
35951次浏览 420人参与
# 地方国企笔面经互助 #
4352次浏览 12人参与
# 如果有时光机,你最想去到哪个年纪? #
20150次浏览 339人参与
# 选完offer后,你后悔学本专业吗 #
21303次浏览 154人参与
# 百度开奖 #
178680次浏览 1118人参与
# 如何一边实习一边秋招 #
995473次浏览 12660人参与
# 招聘要求与实际实习内容不符怎么办 #
10641次浏览 276人参与
# 许愿池 #
214417次浏览 2534人参与
# 学历or实习经历,哪个更重要 #
53268次浏览 416人参与
# 海康威视求职进展汇总 #
400215次浏览 3406人参与
# 正在实习的你,几点下班 #
52926次浏览 395人参与
# 如果再来一次,你还会学硬件吗 #
95042次浏览 1167人参与
# 科大讯飞求职进展汇总 #
237937次浏览 2505人参与
# 国央企薪资爆料 #
10971次浏览 78人参与
# 软开人,秋招你打算投哪些公司呢 #
44006次浏览 544人参与
# 软件开发薪资爆料 #
2189277次浏览 21855人参与
# 租房前辈的忠告 #
109277次浏览 5232人参与
# 得物求职进展汇总 #
67152次浏览 686人参与
# 机械制造秋招总结 #
30551次浏览 354人参与
# 米哈游求职进展汇总 #
176778次浏览 1464人参与