全部评论
发一下前三题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);
}
}
前三题都还可以……一个小时就做完了,但是最后一题想贪全最后没有做完,还是太菜了
80 80 100路过,第四题看不懂题目
都好厉害 80 0 40 0
就想知道最后一题什么意思 在树上跑步🙄
80 100 40 0求第三题思路
订闹钟 密码 王大锤 跑步 有没有一样的呀?
80 100 100 10 感觉凉了... 第一题剩下20到底啥玩意啊啊啊 最后一题是Tarjan LCA? 反正floyd肯定搞不过去
80 100 100 0 第一题调奔溃了
吼hou吼hou mark
80,100,100,0;想不通为啥第一题80
第三题是我没看懂吗,球ac100的给我解释下
大佬们跪求第三题解法
100 100 40 0
第二题和前K-1个取xor即可, 50分的可能是多把前导0去掉了 第三题拓扑排序
第一题80%的同学,最后应该再补一个输出第一个闹钟时间,这样就100%
1 -> 80, 2 -> 80+, 3 -> 100 能告诉我为啥,前两个没过吗。。。 1. import sys
n = int(sys.stdin.readline().strip())
clock_times = []
for _ in range(n):
clock_times.append(list(map(int, sys.stdin.readline().strip().split())))
walk_minutes = int(sys.stdin.readline().strip())
class_time = list(map(int,sys.stdin.readline().strip().split()))
def get_minutes_from_time(time):
return time[0] * 60 + time[1]
def get_time_from_minutes(minuts):
time = []
time.append(minuts // 60)
time.append(minuts % 60)
return time
def solution(n, clock_times, walk_minutes, class_time):
clock_minutes = []
class_minute = get_minutes_from_time(class_time)
for clock_time in clock_times:
clock_minutes.append(get_minutes_from_time(clock_time))
clock_minutes.sort(reverse=True)
for clock_minute in clock_minutes:
total_minute = clock_minute + walk_minutes
if total_minute <= class_minute:
return get_time_from_minutes(clock_minute)
if __name__ == "__main__":
result = solution(n, clock_times, walk_minutes, class_time)
print(result[0], result[1], sep=" ")
2. import sys
n, k = list(map(int, sys.stdin.readline().strip().split()))
message_encoded = sys.stdin.readline().strip()
def solution(n, k, message_encoded):
if n == 0 or k == 0:
return ""
if k == 1:
return message_encoded
message_encoded = list(message_encoded)
message_encoded = list(map(int, message_encoded))
a_n = []
for i in range(n):
if i == 0:
a_n.append(int(message_encoded[0]))
continue
if i < k:
a_n.append(message_encoded[i] ^ message_encoded[i - 1])
continue
else:
a_n.append(message_encoded[i] ^ message_encoded[i - 1] ^ a_n[i - k])
return "".join(list(map(str, a_n)))
if __name__ == "__main__":
print(solution(n, k, message_encoded))
3. import sys
n = int(sys.stdin.readline().strip())
ages = list(map(int, sys.stdin.readline().strip().split()))
def solution(n, ages):
if n == 0:
return 0
if n == 1:
return 100
bonus = []
for i in range(n):
bonus.append(100)
for i in range(n - 1):
if ages[i + 1] > ages[i]:
bonus[i + 1] = max(bonus[i + 1], bonus[i] + 100)
for i in range(n - 1, 0, -1):
if ages[i - 1] > ages[i]:
bonus[i - 1] = max(bonus[i - 1], bonus[i] + 100)
return sum(bonus)
if __name__ == "__main__":
print(solution(n, ages))
现在的题目好难啊。。树形DP,这些不是竞赛专有名词吗。笔试都要上了。 你们真是太难了。
大佬们,不要装逼了。。真的!!!
我只有第三题AC:我是这么干的:从左往右遍历一次,如果入职时长大于右边且工资小于等于右边的,工资加100, 然后在从右往左遍历一次,如果右边入职时长大于左边且工资小于等于左边的,也加100. 如此遍历直到都满足即可
第三个怎么都40%,不知道有哪些样例特殊
相关推荐