results = nums.stream().map(
- one -> {
- int begin = 1, end = one.length;
- while (begin < end) { // 还是bisect
- final int mid = (end - begin) / 2 + begin;
- final int result = cal(one, mid);
- // 可以认为是在[begin,end)间, 只有两个值, 一个-1, 一个1, 要寻找的是最左边的一个1
- if (result == -1) {
- begin = mid + 1;
- } else if (result == 1) {
- end = mid;
- }
- }
- return begin;
- }).collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- /**
- * Output
- *
- * For each case, output an integer standing for the meters one athlete should at most to run.
- */
- public static void output(Iterable decides) {
- for (var decide : decides) {
- System.out.printf("%d\n", decide);
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- st = new StringTokenizer("");
- }
-
- public boolean hasNext() {
- while (!st.hasMoreTokens()) {
- String nextLine = nextLine();
- if (nextLine == null) {
- return false;
- }
- st = new StringTokenizer(nextLine);
- }
- return true;
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_2/lab_2_1136/test/MainTest.java b/2018fall/lab_2/lab_2_1136/test/MainTest.java
deleted file mode 100644
index 609fc2e..0000000
--- a/2018fall/lab_2/lab_2_1136/test/MainTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
-import tests.Pair;
-import tests.Redirect;
-
-
-import java.io.*;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH,"01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
-
- try (Redirect redirect = Redirect.from(DATA_PATH,"01.data.in", "01.test.out")){
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_2/pom.xml b/2018fall/lab_2/pom.xml
deleted file mode 100644
index adb4bf0..0000000
--- a/2018fall/lab_2/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template
- 2018fall
- ${revision}
- ./../pom.xml
-
- pom
- nanoseeds.algorithm-template.2018fall
- lab_2
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
- lab_2_1131
- lab_2_1129
- lab_2_1132
- lab_2_1133
- lab_2_1136
- lab_2_1134
- lab_2_1135
-
-
-
- nanoseeds.algorithm-template
- test_include_package
- ${revision}
- test
-
-
-
-
diff --git a/2018fall/lab_3/README.md b/2018fall/lab_3/README.md
deleted file mode 100644
index 3f98059..0000000
--- a/2018fall/lab_3/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3: sort
-
-要说本章是sort也很难讲, 只能说本章体现了sort的思路.
-
-## 数据
-
-| order | problem | ac | submit |
-|:-----:|:-------:|:---:|:------:|
-| 1138 | A | 190 | 951 |
-| 1140 | B | 157 | 1607 |
-| 1139 | C | 171 | 703 |
-| 1144 | D | 142 | 959 |
-| 1141 | E | 163 | 408 |
-| 1142 | F | 36 | 419 |
-| 1143 | G | 93 | 1247 |
-
-## 1142
-
-1142这道题明显是难度没把控好, 不然数据也不会是这个鬼样子,1142一下变成只有15%的ac比率, 和1143直接对比成2:5.
-
-前面几道题也是, 没什么区分, 即起不到训练作用, 也没有筛选作用, 出题的可以说是什么好目标也没有达到, 失败至极; 当然,
-成功达成了折磨人的目标.
-
-## 1140-1144
-
-这两个题目非常有趣,一个是合并, 另一个是微分(换句话讲, 求导)
-
-最难的点是把多项式用合理的数据结构存起来, 滤掉无效项, 给输出出来. 如果设计的好, 这两个代码数据结构可以复用,输出可以复用.
-
-但是, 1140有157, 1144只有142, 说明同学们功力明显不够, 有些人是大力出奇迹的.
-
-## 每个题目都应该独享一个文件夹
-
-做本章的问题真切地体会到, 每一个问题都应该配一个文件夹, 不为其他的, 就为了固化思路, 同时README.md也能在web上渲染出来.
diff --git a/2018fall/lab_3/lab_3_1138/pom.xml b/2018fall/lab_3/lab_3_1138/pom.xml
deleted file mode 100644
index d14d8db..0000000
--- a/2018fall/lab_3/lab_3_1138/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1138
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1138/resources/01.data.in b/2018fall/lab_3/lab_3_1138/resources/01.data.in
deleted file mode 100644
index 9d6c868..0000000
--- a/2018fall/lab_3/lab_3_1138/resources/01.data.in
+++ /dev/null
@@ -1,7 +0,0 @@
-2
-4 5
-1 2 3 4
-1 2 3 4 5
-1 3
-2
-1 3 4
diff --git a/2018fall/lab_3/lab_3_1138/resources/01.data.out b/2018fall/lab_3/lab_3_1138/resources/01.data.out
deleted file mode 100644
index e6f1167..0000000
--- a/2018fall/lab_3/lab_3_1138/resources/01.data.out
+++ /dev/null
@@ -1,2 +0,0 @@
-1 1 2 2 3 3 4 4 5
-1 2 3 4
diff --git a/2018fall/lab_3/lab_3_1138/src/Main.java b/2018fall/lab_3/lab_3_1138/src/Main.java
deleted file mode 100644
index 1328683..0000000
--- a/2018fall/lab_3/lab_3_1138/src/Main.java
+++ /dev/null
@@ -1,163 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Scanner;
-import java.util.StringTokenizer;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final List fst;
- private final List snd;
-
- public one(List fst, List snd) {
- this.fst = fst;
- this.snd = snd;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 15));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int m = input.nextInt();
- assert ((1 <= n) && (n <= 100_000));
- assert ((1 <= m) && (m <= 100_000));
- final List fst = new ArrayList<>(n); // 还想优化这里可以用裸数组
- final List snd = new ArrayList<>(m);
- for (int j = 0; j < n; j++) {
- final int number = input.nextInt();
- assert ((1 <= number) && (number <= 1_000_000_000));
- fst.add(number);
- }
- for (int j = 0; j < m; j++) {
- final int number = input.nextInt();
- assert ((1 <= number) && (number <= 1_000_000_000));
- snd.add(number);
- }
- cases.add(new one(fst, snd));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 15));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int m = input.nextInt();
- assert ((1 <= n) && (n <= 100_000));
- assert ((1 <= m) && (m <= 100_000));
- final List fst = new ArrayList<>(n);
- final List snd = new ArrayList<>(m);
- for (int j = 0; j < n; j++) {
- final int number = input.nextInt();
- assert ((1 <= number) && (number <= 1_000_000_000));
- fst.add(number);
- }
- for (int j = 0; j < m; j++) {
- final int number = input.nextInt();
- assert ((1 <= number) && (number <= 1_000_000_000));
- snd.add(number);
- }
- cases.add(new one(fst, snd));
- }
- return cases;
- }
-
- public static List> cal(List nums) {
- final List> results = nums.stream()
- .map(one -> {
- final var fst = one.fst;
- final var snd = one.snd;
- final int length1 = fst.size(), length2 = snd.size();
- final List result = new ArrayList<>(length1 + length2);
- int x = 0, y = 0;
- while (x < length1 && y < length2) {
- if (fst.get(x) < snd.get(y)) {
- result.add(fst.get(x));
- x++;
- } else if (fst.get(x) > snd.get(y)) {
- result.add(snd.get(y));
- y++;
- } else {
- result.add(fst.get(x));
- result.add(snd.get(y));
- x++;
- y++;
- }
- }
- for (; x < length1; x++) {result.add(fst.get(x));}
- for (; y < length2; y++) {result.add(snd.get(y));}
- return result;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List> decides) {
- for (var decide : decides) {
- final StringBuilder builder = new StringBuilder();
- for (int i = 1; i < decide.size(); i++) {
- builder.append(decide.get(i - 1)).append(" ");
- }
- builder.append(decide.get(decide.size() - 1)).append("\n");
- System.out.print(builder);
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1138/test/MainTest.java b/2018fall/lab_3/lab_3_1138/test/MainTest.java
deleted file mode 100644
index 489201f..0000000
--- a/2018fall/lab_3/lab_3_1138/test/MainTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
-import tests.Pair;
-import tests.Redirect;
-
-
-import java.io.*;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH,"01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
-
- try (Redirect redirect = Redirect.from(DATA_PATH,"01.data.in", "01.test.out")){
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1139/README.md b/2018fall/lab_3/lab_3_1139/README.md
deleted file mode 100644
index a8b4289..0000000
--- a/2018fall/lab_3/lab_3_1139/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3_1139
-
-难以分析想表达点什么, 这和sort有关系吗?
diff --git a/2018fall/lab_3/lab_3_1139/pom.xml b/2018fall/lab_3/lab_3_1139/pom.xml
deleted file mode 100644
index 923ccb8..0000000
--- a/2018fall/lab_3/lab_3_1139/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1139
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1139/resources/01.data.in b/2018fall/lab_3/lab_3_1139/resources/01.data.in
deleted file mode 100644
index 96f993b..0000000
--- a/2018fall/lab_3/lab_3_1139/resources/01.data.in
+++ /dev/null
@@ -1,4 +0,0 @@
-2 CBBCJJKZKZ
-3 GAKKBDDBAGNN
-3 NACCQNDDQAEE
-0
diff --git a/2018fall/lab_3/lab_3_1139/resources/01.data.out b/2018fall/lab_3/lab_3_1139/resources/01.data.out
deleted file mode 100644
index 7938dcd..0000000
--- a/2018fall/lab_3/lab_3_1139/resources/01.data.out
+++ /dev/null
@@ -1,3 +0,0 @@
-0
-1
-0
diff --git a/2018fall/lab_3/lab_3_1139/src/Main.java b/2018fall/lab_3/lab_3_1139/src/Main.java
deleted file mode 100644
index 251ca6f..0000000
--- a/2018fall/lab_3/lab_3_1139/src/Main.java
+++ /dev/null
@@ -1,150 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final Integer booksNum;
- private final String customes;
-
- private one(Integer booksNum, String customes) {
- this.booksNum = booksNum;
- this.customes = customes;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final List cases = new ArrayList<>();
- while (input.hasNext()) {
- final int number = input.nextInt();
- assert ((0 <= number) && (number <= 20));
- if (number != 0) {
- final String custom = input.next();
- cases.add(new one(number, custom));
- }
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final List cases = new ArrayList<>();
- while (input.hasNext()) {
- final int number = input.nextInt();
- assert ((0 <= number) && (number <= 20));
- if (number != 0) {
- final String custom = input.next();
- cases.add(new one(number, custom));
- }
- }
- return cases;
- }
-
-
- public static List cal(List nums) {
- final List results = nums.stream()
- .map(one -> {
- Integer booksNum = one.booksNum;
- final String customes = one.customes;
- final int[] users = new int[26]; // raw for-range can use the same array
- Arrays.fill(users, 0);
- int lines = 0;
- if (booksNum == 0) {
- return customes.length() / 2;
- }
- final int customesDouble = customes.length();
- for (int j = 0; j < customesDouble; j++) {
- final int order = customes.charAt(j) - 'A';
- if (users[order] == 0) {
- if (booksNum > 0) {
- booksNum -= 1;
- users[order] = 1;
- } else {
- users[order] = -1;
- }
- } else if (users[order] == 1) {
- users[order] = 0;
- booksNum += 1;
- } else {
- users[order] = 0;
- lines += 1;
- }
- }
- return lines;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List decides) {
- final StringBuilder builder = new StringBuilder();
- for (var decide : decides) {
- builder.append(decide).append("\n");
- }
- System.out.print(builder);
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- st = new StringTokenizer("");
- }
-
- public boolean hasNext() {
- while (!st.hasMoreTokens()) {
- String nextLine = nextLine();
- if (nextLine == null) {
- return false;
- }
- st = new StringTokenizer(nextLine);
- }
- return true;
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1139/test/MainTest.java b/2018fall/lab_3/lab_3_1139/test/MainTest.java
deleted file mode 100644
index 96257a5..0000000
--- a/2018fall/lab_3/lab_3_1139/test/MainTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1140/pom.xml b/2018fall/lab_3/lab_3_1140/pom.xml
deleted file mode 100644
index 17a914a..0000000
--- a/2018fall/lab_3/lab_3_1140/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1140
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1140/resources/01.data.in b/2018fall/lab_3/lab_3_1140/resources/01.data.in
deleted file mode 100644
index e2c6744..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/01.data.in
+++ /dev/null
@@ -1,13 +0,0 @@
-2
-2
-1 2
-2 3
-2
-2 2
-1 4
-2
-2 0
--2 1
-2
-3 1
-1 2
diff --git a/2018fall/lab_3/lab_3_1140/resources/01.data.out b/2018fall/lab_3/lab_3_1140/resources/01.data.out
deleted file mode 100644
index 1d4555e..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/01.data.out
+++ /dev/null
@@ -1,2 +0,0 @@
-3x^2+2x^3+x^4
-2+x+x^2
diff --git a/2018fall/lab_3/lab_3_1140/resources/02.data.in b/2018fall/lab_3/lab_3_1140/resources/02.data.in
deleted file mode 100644
index f82a280..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/02.data.in
+++ /dev/null
@@ -1,13 +0,0 @@
-2
-2
--1 2
--2 3
-2
--2 2
--1 4
-2
--2 0
-2 1
-2
--3 1
--1 2
diff --git a/2018fall/lab_3/lab_3_1140/resources/02.data.out b/2018fall/lab_3/lab_3_1140/resources/02.data.out
deleted file mode 100644
index 281fa1f..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/02.data.out
+++ /dev/null
@@ -1,2 +0,0 @@
--3x^2-2x^3-x^4
--2-x-x^2
diff --git a/2018fall/lab_3/lab_3_1140/resources/03.data.in b/2018fall/lab_3/lab_3_1140/resources/03.data.in
deleted file mode 100644
index 6b4e9e6..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/03.data.in
+++ /dev/null
@@ -1,13 +0,0 @@
-2
-2
--1 2
--2 3
-2
-1 2
-2 3
-2
--2 0
-2 1
-2
-2 0
--2 1
diff --git a/2018fall/lab_3/lab_3_1140/resources/03.data.out b/2018fall/lab_3/lab_3_1140/resources/03.data.out
deleted file mode 100644
index aa47d0d..0000000
--- a/2018fall/lab_3/lab_3_1140/resources/03.data.out
+++ /dev/null
@@ -1,2 +0,0 @@
-0
-0
diff --git a/2018fall/lab_3/lab_3_1140/src/Main.java b/2018fall/lab_3/lab_3_1140/src/Main.java
deleted file mode 100644
index 01bc9e8..0000000
--- a/2018fall/lab_3/lab_3_1140/src/Main.java
+++ /dev/null
@@ -1,205 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final List> fst;
- private final List> snd;
-
- public one(List> fst, List> snd) {
- this.fst = fst;
- this.snd = snd;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((0 <= n) && (n <= 1_000));
- final List> fst = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-10000 <= coefficient) && (coefficient <= 10000));
- assert ((0 <= exponent) && (exponent <= 1000_000_000));
- fst.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- final int m = input.nextInt();
- assert ((0 <= m) && (m <= 1_000));
- final List> snd = new ArrayList<>(m);
- for (int j = 0; j < m; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-10000 <= coefficient) && (coefficient <= 10000));
- assert ((0 <= exponent) && (exponent <= 1000_000_000));
- snd.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- cases.add(new one(fst, snd));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((0 <= n) && (n <= 1_000));
- final List> fst = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-10000 <= coefficient) && (coefficient <= 10000));
- assert ((0 <= exponent) && (exponent <= 1000_000_000));
- fst.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- final int m = input.nextInt();
- assert ((0 <= m) && (m <= 1_000));
- final List> snd = new ArrayList<>(m);
- for (int j = 0; j < m; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-10000 <= coefficient) && (coefficient <= 10000));
- assert ((0 <= exponent) && (exponent <= 1000_000_000));
- snd.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- cases.add(new one(fst, snd));
- }
- return cases;
- }
-
- public static List>> cal(List nums) {
- final List>> results = nums.stream()
- .map(one -> {
- final var fst = one.fst;
- final var snd = one.snd;
- final Map map = new HashMap<>(fst.size() + snd.size());
- for (var entry : fst) {
- final long coefficient = entry.getKey(); //系数, 2x^3的2
- final long exponent = entry.getValue(); //指数, 2x^3的3
- map.merge(exponent, coefficient, Long::sum); // copilot find exponent should be the key...
- }
- for (var entry : snd) {
- final long coefficient = entry.getKey();
- final long exponent = entry.getValue();
- map.merge(exponent, coefficient, Long::sum); // copilot find exponent should be the key...
- }
- // 其实并不需要排序, 排序是为了之后O(n)的归并, 用了map之后可以高效合并, 所以不需要了.
- final List> outputList = map.entrySet().stream()
- .filter(entry -> entry.getValue() != 0) // 显然不需要使出0, 0x,0x^2这种东西
- .sorted(Comparator.comparingLong(Map.Entry::getKey)) // 按指数排序
- .collect(Collectors.toUnmodifiableList());
- //
- return outputList;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- private static void putResultToStr(Map.Entry entry, StringBuilder builder) {
- final long expon = entry.getKey();
- final long coeff = entry.getValue(); //系数, 2x^3的2
- assert (0 != coeff);
- assert (0 <= expon);
- if (coeff > 0) {
- builder.append("+");
- }
- //采用正确处理措施以及预处理之后,逻辑简化了
- if (expon == 0) { // 特殊情况, 1,2,3 ...
- builder.append(coeff);
- } else if (expon == 1) {
- if (coeff == 1) { // x
- builder.append("x");
- } else if (coeff == -1) { // -x
- builder.append("-x");
- } else { // -2x 2x 3x -5x
- builder.append(coeff).append("x");
- }
- } else {
- if (coeff == 1) { // x^2
- builder.append("x^").append(expon);
- } else if (coeff == -1) { // -x^2
- builder.append("-x^").append(expon);
- } else { // -2x^2 2x^2 3x^2 -5x^2
- builder.append(coeff).append("x^").append(expon);
- }
- }
- }
-
- public static void output(List>> decides) {
- for (var decide : decides) {
- if (decide.isEmpty()) {
- System.out.print("0\n");
- continue;
- }
- final StringBuilder builder = new StringBuilder();
- for (var entry : decide) {
- putResultToStr(entry, builder);
- }
- builder.append("\n");
- if (builder.charAt(0) == '+') {
- final String result = builder.substring(1); // 要是有string_view就好了
- System.out.print(result);
- } else {
- System.out.print(builder);
- }
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1140/test/MainTest.java b/2018fall/lab_3/lab_3_1140/test/MainTest.java
deleted file mode 100644
index 8eca48e..0000000
--- a/2018fall/lab_3/lab_3_1140/test/MainTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-
- @Test
- public void test_negtives() throws IOException {
-
- try (Redirect redirect = Redirect.from(DATA_PATH, "02.data.in", "02.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("02.data.out", "02.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-
- @Test
- public void test_zeros() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "03.data.in", "03.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("03.data.out", "03.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1141/README.md b/2018fall/lab_3/lab_3_1141/README.md
deleted file mode 100644
index 8a71909..0000000
--- a/2018fall/lab_3/lab_3_1141/README.md
+++ /dev/null
@@ -1,62 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3_1141
-
-分析一下下面的用例
-
-``` log
-3
-3 4 0
-3 4 1
-3 3 1
-```
-
-## 3 4 0
-
-注意到`numbered (m + 1)th`,可见是从1开始计数的.
-
-three node, destory 4 times, earty is fst
-
-+ 0 1 2
- + 0 1 2 0 1
- + 1 is destory
- + 2 0
-+ 2 0
- + 2 0 2 0 2
- + 2 is destory
- + 0
-+ 0
- + 0 0 0 0 0
- + 0 is destory
-
-0 is the last.
-
-编号从0开始, 但是计数1开始记到m+1, 麻烦.
-
-## 3 4 1
-
-过程如上, 1是倒数第二个, 不是.
-
-### 3 3 1
-
-+ 0 1 2
- + 0 1 2 0
- + 0 is destory
- + 1 2
-+ 1 2
- + 1 2 1 2
- + 2 is destory
- + 1
-+ 1
- + 1 1 1 1 1
- + 1 is destory
-
-这里可以发现, 需要把下一个计数的作为第一个, 才能推理通顺.
-
-PS: 需要注意到, 并不是只进行math.min(n,m)次, 而是准确的进行n次, 每次1个.
-
-## 约瑟夫环问题
-
-这个问题其实是约瑟夫环问题, 数学证明之后可以比较简单的解决.
diff --git a/2018fall/lab_3/lab_3_1141/pom.xml b/2018fall/lab_3/lab_3_1141/pom.xml
deleted file mode 100644
index 2bf25ac..0000000
--- a/2018fall/lab_3/lab_3_1141/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1141
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1141/resources/01.data.in b/2018fall/lab_3/lab_3_1141/resources/01.data.in
deleted file mode 100644
index 6d13e14..0000000
--- a/2018fall/lab_3/lab_3_1141/resources/01.data.in
+++ /dev/null
@@ -1,4 +0,0 @@
-3
-3 4 0
-3 4 1
-3 3 1
diff --git a/2018fall/lab_3/lab_3_1141/resources/01.data.out b/2018fall/lab_3/lab_3_1141/resources/01.data.out
deleted file mode 100644
index 0ef5c04..0000000
--- a/2018fall/lab_3/lab_3_1141/resources/01.data.out
+++ /dev/null
@@ -1,3 +0,0 @@
-Yes
-No
-Yes
diff --git a/2018fall/lab_3/lab_3_1141/src/Main.java b/2018fall/lab_3/lab_3_1141/src/Main.java
deleted file mode 100644
index 878a342..0000000
--- a/2018fall/lab_3/lab_3_1141/src/Main.java
+++ /dev/null
@@ -1,159 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Scanner;
-import java.util.StringTokenizer;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final int n, m, e;
-
- public one(int n, int m, int e) {
- this.n = n;
- this.m = m;
- this.e = e;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int m = input.nextInt();
- final int e = input.nextInt();
- assert ((1 <= n) && (n <= 100));
- assert ((1 <= m) && (m <= 100));
- assert ((0 <= e) && (e <= n));
- cases.add(new one(n, m, e));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int m = input.nextInt();
- final int e = input.nextInt();
- assert ((1 <= n) && (n <= 100));
- assert ((1 <= m) && (m <= 100));
- assert ((0 <= e) && (e <= n));
- cases.add(new one(n, m, e));
- }
- return cases;
- }
-
- private static final class node {
- private static final node head = new node(0x3f3f3f3f);
- public node pre, next;
- private final int value;
-
- public node(int value) {
- this.value = value;
- }
- }
-
- public static List cal(List nums) {
- final List results = nums.stream()
- .map(one -> {
- final int n = one.n, m = one.m, e = one.e;
- node fst = node.head;
- for (int i = 0; i < n; i++) {
- fst.next = new node(i);
- fst.next.pre = fst;
- fst = fst.next;
- }
- fst.next = node.head.next;
- node.head.next.pre = fst;
- for (int i = 0; i < n; i++) { // after math.min(n,m), it must be done
- final int index = (m) % (n - i);
- node rolling = node.head;
- for (int j = 0; j < index; j++) {
- rolling = rolling.next;
- }
- final node temp = rolling.next;
- if (temp != null) {
- //if (temp.next != null) {
- temp.next.pre = temp.pre;
- //}
- //if (temp.pre != null) {
- temp.pre.next = temp.next;
- node.head.next = temp.next;
- //}
- temp.next = null;
- temp.pre = null;
- }
- }
- return node.head.next.value == e;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List decides) {
- for (var decide : decides) {
- if (decide) {
- System.out.print("Yes\n");
- } else {
- System.out.print("No\n");
- }
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1141/test/MainTest.java b/2018fall/lab_3/lab_3_1141/test/MainTest.java
deleted file mode 100644
index 96257a5..0000000
--- a/2018fall/lab_3/lab_3_1141/test/MainTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1142/README.md b/2018fall/lab_3/lab_3_1142/README.md
deleted file mode 100644
index 7a809bb..0000000
--- a/2018fall/lab_3/lab_3_1142/README.md
+++ /dev/null
@@ -1,109 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3_1142
-
-## 解析输入
-
-### part1
-
-```log
-Input:
-1
-5 2
-1 2 3 4 5
-Output:
-30
-```
-
-5*5=25<30, 很显然这里并不是说简单的拿(1,2)拿一个2,(2,3)拿一个3这样来搞的, 而是另一种方式.
-
-`every consecutive interval of the n horses, and remember only the intervals equal or longer than k should be considered.`
-
-猜想是拿所有的length>=k的interval, 然后拿kth
-
-对length2: 1+2+3+4
-对length3: 2+3+4
-对length4: 3+4
-对length5: 4
-
-求和为 10+9+7+4=30
-
-bingo, 看题目里说, 似乎整个序列就是a[n]=n+1
-
-## sloves
-
-### part1
-
-从上面的分析也可以看出来, 可以形成一个金字塔, 原理是只考虑length>=k,而一旦前面确定之后, 后面再追加多少个其实都不变了, 可以简单用还有多少个来乘出来.
-
-因此, 对于一个长度为n的[1,2,3,4....n]序列, 对长度为k进行采样.
-
-需要取到最多n+1-k个值, 分别是[1...n+1-k]
-
-而对于一个n+1-k的值来说, 算上原本的一个, 最多有n+1-k个值,所以是(n+1-k)^2
-
-以此类推, 是(n+1-k)^2+(n-k)^2+...+(1)^2=(n+1-k)(n+2-k)(2n+3-2k)/6
-
-对n=5,k=2带入, 可得4*5*9/6=30
-
-Wrong Anseer
-
-### part2
-
-重新审题, `to simplify, the strength of the n horses is a permutation of 1 to n`, 说明只是一个{1,2,...,n-1, n}的排列,而不是顺序的.
-
-这样的话就不是有序的数组了, 不能直接取值来做判断. 也不能累乘, 第一想法是搞一个优先队列,
-
-这里有几种做法,
-+ 可以考虑优先扫描相同长度的序列, 序列长度不断递增
-+ 可以考虑优先扫描相同起始的序列, 序列从k->n不断递增, 触达max之后起始位置+1
-+ 还可以考虑来回震荡,{1,2},{2,3},{3,4}...{n-1,n},--> {n,n-1,n-2}
-
-第一种情况最大的问题是, 由于需要在相同长度的序列之间共享优先队列, 所以需要`push(rightestObject) && remove(leftestObject)`, `remove(Object)`的时间复杂度太高了, 为O(k)
-
-这些个对象会遍历O(n^2)次, O(n^2*(k+logk))顶不住.
-
-第二种不会共享优先队列, 循环被调用(n+1-k)次, 每次有klogk的时间用来建优先队列, (n-k-i)次, 每次2logk的时间来add(object),poll()
-
-$∑(i from 1 to n+1-k) (klogk + (n-k-i)*2logk)$, 基本上也是O(n^2)级别, 会超时
-
-第三种和第一种无异, 也会超时.
-
-### part3
-
-现在让我们重新开始考虑, 我们需要找到的是, 在这(n-k)*(n-k+1)/2个序列中(提前过滤了小于k长度的序列), 第kth-max之值的和.
-
-如果我们不去聚焦于这些个序列, 而是聚焦于从1-N的这N个数字.
-
-我们先选中一个值x, 很显然, 由于这个序列不存在重复的值, 因此, 只有存在(k-1)个其他的值比x大, 此时才x才能成为kth-max.
-
-而这k-1个其他的值之外, 无论这个序列左边拓展任意的值, 右边接上一些小于x的, 还是左右中间存在一些值, 都不影响x当kth-max.
-
-以以下数组举例`5 2 4 1 3`, 分析一下4, 左边只有一个5比它大, 右边没有. 由于k是2, 所以
-
-+ 由于右边没有值>4, 因此如果左边界取2/4, 都是无效
-+ 当左边界取到5时, 有边界右4,1,3三个选择.
-
-当使用一个惯用伎俩, 对左边界加一个0,pre自指,有边界加一个n+1,next自指, 这样就可以统一处理了.
-
-对4来说, 左边第一个是5, 距离是2, 对5来说左边第一个是0, 距离是1, 但是从左到右的看, 应该将距离置为[1,2]
-分别代表, 5为左边界只有一个可选项, 4作为左边界, 可以向左边附一个2,从而达到两个可选项.
-
-右边第一个是6, 距离是3, 对6来说右边就是自己, 没有了, 按从左到右的顺序置为[3,0]
-分别代表, 以4为有边界, 再附加上两个(<4)的值, 一共有三个可选项, 之后没有了.
-
-这种情况下, 两边形成一个滑动窗口, 窗口长度k, 两者之积就是取4左边第(x-1)(0指自己)个大于他的值为左边界/右边界, 再附加上比它小的值的可能性.
-
-两个向量做一次点乘, 得到结果.
-
-然后问题来了, 如果要从左到右简单的分析的话, 得把整个数组遍历一遍, 时间复杂度又变成O(n)了..., 来n次, 又是O(n^2)
-
-这里我们借用排序的思想, 如果我们先从最小的开始, 对他来说, 所有值都比他大, 所以它只需要想左扫描k个, 右扫描k个就行, 只要不是在边缘, 每一个都是1.
-
-但是这之后呢? 如果不排除掉上一轮的值, 那这一论就变k+1了, 还是会变慢, 到时候均摊复杂度又上去了, 如果要复制一个新数组, 还是O(n)时间.
-
-这时就要引入链表了, 如果我们把数组存在链表内, 每次扫描的时候, 把上一轮的值从链表中删除, 这样就可以保证每次扫描的时候, 都是k个值, 也能保证不复制数组, 使用一个O(1)时间.
-
-因此, 每次扫描, 都是扫描当前的最小值, 链表里面的值都是比当前值大的, 比当前值小的都体现了position里面了.
diff --git a/2018fall/lab_3/lab_3_1142/pom.xml b/2018fall/lab_3/lab_3_1142/pom.xml
deleted file mode 100644
index b514ed2..0000000
--- a/2018fall/lab_3/lab_3_1142/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1142
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1142/resources/01.data.in b/2018fall/lab_3/lab_3_1142/resources/01.data.in
deleted file mode 100644
index d0810f6..0000000
--- a/2018fall/lab_3/lab_3_1142/resources/01.data.in
+++ /dev/null
@@ -1,3 +0,0 @@
-1
-5 2
-1 2 3 4 5
diff --git a/2018fall/lab_3/lab_3_1142/resources/01.data.out b/2018fall/lab_3/lab_3_1142/resources/01.data.out
deleted file mode 100644
index 64bb6b7..0000000
--- a/2018fall/lab_3/lab_3_1142/resources/01.data.out
+++ /dev/null
@@ -1 +0,0 @@
-30
diff --git a/2018fall/lab_3/lab_3_1142/resources/02.data.in b/2018fall/lab_3/lab_3_1142/resources/02.data.in
deleted file mode 100644
index 72d71c6..0000000
--- a/2018fall/lab_3/lab_3_1142/resources/02.data.in
+++ /dev/null
@@ -1,3 +0,0 @@
-1
-5 2
-5 2 4 1 3
diff --git a/2018fall/lab_3/lab_3_1142/resources/02.data.out b/2018fall/lab_3/lab_3_1142/resources/02.data.out
deleted file mode 100644
index 6f4247a..0000000
--- a/2018fall/lab_3/lab_3_1142/resources/02.data.out
+++ /dev/null
@@ -1 +0,0 @@
-26
diff --git a/2018fall/lab_3/lab_3_1142/src/Main.java b/2018fall/lab_3/lab_3_1142/src/Main.java
deleted file mode 100644
index 051eb88..0000000
--- a/2018fall/lab_3/lab_3_1142/src/Main.java
+++ /dev/null
@@ -1,208 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-public final class Main {
- private static final class one {
- private final List powers;
- private final int k;
-
- public one(List powers, int k) {
- this.powers = powers;
- this.k = k;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 10));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int k = input.nextInt();
- assert ((1 <= n) && (n <= 500_000));
- assert ((0 <= k) & (k <= Math.min(n, 80)));
- final List powers = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int power = input.nextInt();
- assert ((0 <= power) & (power <= 500_000));
- powers.add(power);
- }
- cases.add(new one(powers, k));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 10));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- final int k = input.nextInt();
- assert ((1 <= n) && (n <= 500_000));
- assert ((0 <= k) & (k <= Math.min(n, 80)));
- final List powers = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int power = input.nextInt();
- assert ((0 <= power) & (power <= 500_000));
- powers.add(power);
- }
- cases.add(new one(powers, k));
- }
- return cases;
- }
-
- private static final class node {
- private node pre, next;
- private final int position;
-
- public node(int position) {
- this.pre = null;
- this.next = null;
- this.position = position;
- }
- }
-
- private static int kth(node nod, int k, int n) {
- int countL = k, countR = 0;
- final int[] lefts = new int[k];
- final int[] rights = new int[k];
- for (node left = nod; left != left.pre && countL > 0; left = left.pre, countL--) {
- lefts[countL - 1] = left.position - left.pre.position;
- }
- for (node right = nod; right != right.next && countR < k; right = right.next, countR++) {
- rights[countR] = right.next.position - right.position;
- }
- int sums = 0;
- for (int left = 0; left < k; left++) {
- sums += lefts[left] * rights[left];
- }
- return sums;
- }
-
- public static List cal(List nums) {
- final List results = nums.stream()
- .map(one -> {
- final int n = one.powers.size();
- final int k = one.k;
- final node[] nodes = new node[n + 2];
- final Map num_to_pos = new HashMap<>();// 因为是一对一的的满射, 可以用一个数组替代
- for (int i = 1; i <= n; i++) {
- num_to_pos.put(one.powers.get(i - 1), i);
- }
- nodes[0] = new node(0);
- for (int i = 1; i <= n; i++) {
- nodes[i] = new node(i);
- }
- nodes[n + 1] = new node(n + 1);
- nodes[0].pre = nodes[0];
- for (int i = 1; i <= n; i++) {
- nodes[i].pre = nodes[i - 1];
- nodes[i].next = nodes[i + 1];
- }
- nodes[n + 1].next = nodes[n + 1];
- long sum = 0;
- for (int i = 1; i <= n; i++) { // 遍历左k个, 右k个, 记录长度
- final int order = num_to_pos.get(i);// from the number, find the position
- sum += i * kth(nodes[order], k, n);
- nodes[order].pre.next = nodes[order].next;
- nodes[order].next.pre = nodes[order].pre;
- nodes[order].pre = null;
- nodes[order].next = null;
- }
- return sum;
- })
- .collect(Collectors.toList());
- return results;
- }
-
- public static List cal_slow(List nums) {
- final List results = nums.stream()
- .map(one -> {
- final int n = one.powers.size();
- final int k = one.k;
- if (n == k) {
- return (long) one.powers.get(0);
- }
- long sum = 0;
- final int internels = n + 1 - k;
- for (int i = 0; i < internels; i++) {
- final PriorityQueue queue = new PriorityQueue<>(k + 2);
- //final PriorityQueue maxQueue = new PriorityQueue<>(Comparator.reverseOrder());
- for (int j = i; j < k + i; j++) {
- queue.add(one.powers.get(j));
- }
- sum += queue.peek();
- for (int j = k + i; j < n; j++) {
- queue.add(one.powers.get(j));
- queue.poll();
- //maxQueue.add(minumum);
- sum += queue.peek();
- }
- }
- return sum;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List decides) {
- for (var decide : decides) {
- System.out.printf("%d\n", decide);
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1142/test/MainTest.java b/2018fall/lab_3/lab_3_1142/test/MainTest.java
deleted file mode 100644
index 547e21d..0000000
--- a/2018fall/lab_3/lab_3_1142/test/MainTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
- @Test
- public void test_3() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "02.data.in", "02.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("02.data.out", "02.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1143/README.md b/2018fall/lab_3/lab_3_1143/README.md
deleted file mode 100644
index afbb028..0000000
--- a/2018fall/lab_3/lab_3_1143/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3_1143
-
-很容易想到两个优先队列, 一个叫min的最小堆, 一个max最大堆.
-
-最小堆堆顶>最大堆堆顶, 保证最小堆size == 最大堆size || 最小堆size-最大堆size == 1
-
-这样最小堆堆顶就是中位数.
diff --git a/2018fall/lab_3/lab_3_1143/pom.xml b/2018fall/lab_3/lab_3_1143/pom.xml
deleted file mode 100644
index 85db968..0000000
--- a/2018fall/lab_3/lab_3_1143/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1143
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1143/resources/01.data.in b/2018fall/lab_3/lab_3_1143/resources/01.data.in
deleted file mode 100644
index 35360b0..0000000
--- a/2018fall/lab_3/lab_3_1143/resources/01.data.in
+++ /dev/null
@@ -1,3 +0,0 @@
-1
-5
-1 2 3 4 5
diff --git a/2018fall/lab_3/lab_3_1143/resources/01.data.out b/2018fall/lab_3/lab_3_1143/resources/01.data.out
deleted file mode 100644
index b85905e..0000000
--- a/2018fall/lab_3/lab_3_1143/resources/01.data.out
+++ /dev/null
@@ -1 +0,0 @@
-1 2 3
diff --git a/2018fall/lab_3/lab_3_1143/resources/02.data.in b/2018fall/lab_3/lab_3_1143/resources/02.data.in
deleted file mode 100644
index f6788c0..0000000
--- a/2018fall/lab_3/lab_3_1143/resources/02.data.in
+++ /dev/null
@@ -1,3 +0,0 @@
-1
-5
-5 2 4 1 3
diff --git a/2018fall/lab_3/lab_3_1143/resources/02.data.out b/2018fall/lab_3/lab_3_1143/resources/02.data.out
deleted file mode 100644
index aacd980..0000000
--- a/2018fall/lab_3/lab_3_1143/resources/02.data.out
+++ /dev/null
@@ -1 +0,0 @@
-5 4 3
diff --git a/2018fall/lab_3/lab_3_1143/src/Main.java b/2018fall/lab_3/lab_3_1143/src/Main.java
deleted file mode 100644
index dc2dd01..0000000
--- a/2018fall/lab_3/lab_3_1143/src/Main.java
+++ /dev/null
@@ -1,150 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final List moneys;
-
- public one(List moneys) {
- this.moneys = moneys;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 10));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((1 <= n) && (n <= 300_000));
- final List moneys = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int money = input.nextInt();
- assert ((0 <= money) & (money <= 300_000));
- moneys.add(money);
- }
- cases.add(new one(moneys));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 10));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((1 <= n) && (n <= 300_000));
- final List moneys = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int money = input.nextInt();
- assert ((0 <= money) & (money <= 300_000));
- moneys.add(money);
- }
- cases.add(new one(moneys));
- }
- return cases;
- }
-
-
- public static List> cal(List nums) {
- final List> results = nums.stream()
- .map(one -> {
- final int n = one.moneys.size();
- final List vals = new ArrayList<>((n + 1) / 2);
- final PriorityQueue min = new PriorityQueue<>(n);
- final PriorityQueue max = new PriorityQueue<>(n, Comparator.reverseOrder());
- min.add(one.moneys.get(0));
- vals.add(one.moneys.get(0));
- for (int i = 1; i < n; i++) {
- final int money = one.moneys.get(i);
- final int minSize = min.size();
- final int maxSize = max.size();
- if (money > min.peek()) {
- min.add(money);
- if (minSize > maxSize) {
- final int value = min.poll();
- max.add(value);
- }
- } else {
- max.add(money);
- if (minSize == maxSize) {
- final int value = max.poll();
- min.add(value);
- }
- }
- if (i % 2 == 0) {
- vals.add(min.peek());
- }
- }
- return vals;
- })
- .collect(Collectors.toList());
- return results;
- }
-
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List> decides) {
- for (var decide : decides) {
- final StringBuilder builder = new StringBuilder();
- for (int x : decide) {
- builder.append(x).append(" ");
- }
- builder.setCharAt(builder.length() - 1, '\n');
- System.out.print(builder);
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1143/test/MainTest.java b/2018fall/lab_3/lab_3_1143/test/MainTest.java
deleted file mode 100644
index 547e21d..0000000
--- a/2018fall/lab_3/lab_3_1143/test/MainTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
- @Test
- public void test_3() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "02.data.in", "02.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("02.data.out", "02.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1144/README.md b/2018fall/lab_3/lab_3_1144/README.md
deleted file mode 100644
index 35e735d..0000000
--- a/2018fall/lab_3/lab_3_1144/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
----
-SPDX-License-Identifier: CC-BY-NC-SA-4.0
----
-
-# lab_3_1144
-
-输出部分逻辑和1139一致, 处理甚至还简单一些...
-
-难以分析想表达点什么, 这和sort有关系吗?
diff --git a/2018fall/lab_3/lab_3_1144/pom.xml b/2018fall/lab_3/lab_3_1144/pom.xml
deleted file mode 100644
index 0132aa0..0000000
--- a/2018fall/lab_3/lab_3_1144/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab3
- lab_3_1144
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_3/lab_3_1144/resources/01.data.in b/2018fall/lab_3/lab_3_1144/resources/01.data.in
deleted file mode 100644
index eae4c93..0000000
--- a/2018fall/lab_3/lab_3_1144/resources/01.data.in
+++ /dev/null
@@ -1,7 +0,0 @@
-2
-2
-1 2
-2 3
-2
-1 -2
--2 3
diff --git a/2018fall/lab_3/lab_3_1144/resources/01.data.out b/2018fall/lab_3/lab_3_1144/resources/01.data.out
deleted file mode 100644
index c6c4143..0000000
--- a/2018fall/lab_3/lab_3_1144/resources/01.data.out
+++ /dev/null
@@ -1,2 +0,0 @@
-2x+6x^2
--2x^-3-6x^2
diff --git a/2018fall/lab_3/lab_3_1144/src/Main.java b/2018fall/lab_3/lab_3_1144/src/Main.java
deleted file mode 100644
index a739ad1..0000000
--- a/2018fall/lab_3/lab_3_1144/src/Main.java
+++ /dev/null
@@ -1,177 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.*;
-import java.util.stream.Collectors;
-
-public final class Main {
- private static final class one {
- private final List> fst;
-
- public one(List> fst) {
- this.fst = fst;
- }
- }
-
- public static List read() {
- final var input = new Scanner(System.in);
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((0 <= n) && (n <= 1_000));
- final List> fst = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-1000 <= coefficient) && (coefficient <= 1000));
- assert ((-1000 <= exponent) && (exponent <= 1000));
- fst.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- cases.add(new one(fst));
- }
- return cases;
- }
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert ((1 <= testcases) && (testcases <= 100));
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- final int n = input.nextInt();
- assert ((0 <= n) && (n <= 1_000));
- final List> fst = new ArrayList<>(n);
- for (int j = 0; j < n; j++) {
- final int coefficient = input.nextInt();
- final int exponent = input.nextInt();
- assert ((-1000 <= coefficient) && (coefficient <= 1000));
- assert ((-1000 <= exponent) && (exponent <= 1000));
- fst.add(new AbstractMap.SimpleImmutableEntry<>(coefficient, exponent));
- }
- cases.add(new one(fst));
- }
- return cases;
- }
-
- public static List>> cal(List nums) {
- final List>> results = nums.stream()
- .map(one -> {
- final var fst = one.fst;
- final Map map = new HashMap<>(fst.size());
- for (var entry : fst) {
- final long coefficient = entry.getKey(); //系数, 2x^3的2
- final long exponent = entry.getValue(); //指数, 2x^3的3
- map.merge(exponent, coefficient, Long::sum); // copilot find exponent should be the key...
- }
- // 其实并不需要排序, 排序是为了之后O(n)的归并, 用了map之后可以高效合并, 所以不需要了.
- final List> outputList = map.entrySet().stream()
- .filter(entry -> entry.getValue() != 0 && entry.getKey() != 0) // 指数为0 or 系数为0都会被过滤掉
- .sorted(Comparator.comparingLong(Map.Entry::getKey)) // 按指数排序
- .map(entry -> new AbstractMap.SimpleImmutableEntry<>(entry.getKey()-1, entry.getValue()*entry.getKey()))
- .collect(Collectors.toUnmodifiableList());
- //
- return outputList;
- })
- .collect(Collectors.toUnmodifiableList());
- return results;
- }
-
- public static void main(String[] args) throws IOException {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- private static void putResultToStr(Map.Entry entry, StringBuilder builder) {
- final long expon = entry.getKey();
- final long coeff = entry.getValue(); //系数, 2x^3的2
- assert (0 != coeff);
- if (coeff > 0) {
- builder.append("+");
- }
- //采用正确处理措施以及预处理之后,逻辑简化了
- if (expon == 0) { // 特殊情况, 1,2,3 ...
- builder.append(coeff);
- } else if (expon == 1) {
- if (coeff == 1) { // x
- builder.append("x");
- } else if (coeff == -1) { // -x
- builder.append("-x");
- } else { // -2x 2x 3x -5x
- builder.append(coeff).append("x");
- }
- } else{
- if (coeff == 1) { // x^2
- builder.append("x^").append(expon);
- } else if (coeff == -1) { // -x^2
- builder.append("-x^").append(expon);
- } else { // -2x^2 2x^2 3x^2 -5x^2
- builder.append(coeff).append("x^").append(expon);
- }
- }
- }
-
- public static void output(List>> decides) {
- for (var decide : decides) {
- if (decide.isEmpty()) {
- System.out.print("0\n");
- continue;
- }
- final StringBuilder builder = new StringBuilder();
- for (var entry : decide) {
- putResultToStr(entry, builder);
- }
- builder.append("\n");
- if (builder.charAt(0) == '+') {
- final String result = builder.substring(1); // 要是有string_view就好了
- System.out.print(result);
- } else {
- System.out.print(builder);
- }
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {return Integer.parseInt(next());}
-
- long nextLong() {return Long.parseLong(next());}
-
- double nextDouble() {return Double.parseDouble(next());}
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_3/lab_3_1144/test/MainTest.java b/2018fall/lab_3/lab_3_1144/test/MainTest.java
deleted file mode 100644
index bd72b0d..0000000
--- a/2018fall/lab_3/lab_3_1144/test/MainTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.*;
-import tests.Pair;
-import tests.Redirect;
-
-import java.io.IOException;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.read()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- try (Redirect redirect = Redirect.from(DATA_PATH, "01.data.in", "01.test.out")) {
- Main.output(Main.cal(Main.reader()));
- final Pair p = redirect.compare_double("01.data.out", "01.test.out");
- Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
- Assertions.assertEquals(p.getFirst(), p.getSecond());
- }
- }
-
-}
diff --git a/2018fall/lab_3/pom.xml b/2018fall/lab_3/pom.xml
deleted file mode 100644
index fcac31e..0000000
--- a/2018fall/lab_3/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template
- 2018fall
- ${revision}
- ./../pom.xml
-
- pom
- nanoseeds.algorithm-template.2018fall
- lab_3
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
- lab_3_1138
- lab_3_1140
- lab_3_1139
- lab_3_1144
- lab_3_1141
- lab_3_1142
- lab_3_1143
-
-
-
- nanoseeds.algorithm-template
- test_include_package
- ${revision}
- test
-
-
-
-
diff --git a/2018fall/lab_4/README.md b/2018fall/lab_4/README.md
deleted file mode 100644
index 4b36224..0000000
--- a/2018fall/lab_4/README.md
+++ /dev/null
@@ -1,77 +0,0 @@
-# 2018fall-lab4
-
-## Stack And Queue
-
-+ [x] problem A: lab_4_1159
-+ [x] problem B: lab_4_1039
-+ [x] problem C: lab_4_1161
-+ [x] problem D: lab_4_1162
-+ [x] problem E: lab_4_1163
-+ [x] problem F: lab_4_1164
-+ [x] problem G: lab_4_1165
-
-## 总体评价
-
-> 这套题目的设计者, 似乎不是想教会学生什么, 而是想告诉他们"你们还有多少东西不会". 对于一个刚学完基础编程, 对"时间复杂度"只有模糊概念的学生来说, 这次实验的体验曲线大概是这样的:
-> 1. A 题: 虚假的希望. "哦, 好像不难, 我能做出来!"
-> 2. B 题: 进入正轨. "这才是课上讲的栈, 逻辑有点绕, 但总算过了."
-> 3. C/D/E 题: 思维的挑战. "为什么会 TLE? 我的逻辑没错啊? 是不是有什么巧妙的办法?"
-> 4. F/G 题: 彻底绝望. "这代码也太复杂了!"
-
----
-
-## 各题目分析
-
-### 问题 A
-
-题面: 在一个字符串中寻找 "lanran" 作为子序列.
-
-这是所有题目中最"仁慈"的一个, AC 率最高 (约 31.6%). 它甚至不是一个栈或队列问题, 只是一个简单的字符串遍历.
-
-### 问题 B
-
-题面: 经典的三种括号 `()[]{}` 匹配问题.
-
-真正的栈应用入门题, 完全符合教科书的经典模型. AC 率约为 20.3%, 显著的 WA 和 RE 数量说明, 即便是经典问题, 学生在处理逻辑细节和边界情况时依然会遇到麻烦.
-
-### ⛰️ 问题 C, D, E: 算法思维的试金石
-
-这三道题开始脱离纯粹的数据结构模板, 转向对特定算法模型的考察, 是区分学生思维能力的关键.
-
-C 题 (`lab_4_1161`, 组合计数): 要求在 `O(n)` 时间内解决一个组合计数问题. 暴力解法会轻易导致 TLE, 迫使学生思考双指针/滑动窗口等优化技巧.
-D 题 (`lab_4_1162`, 迷宫寻路): 一个有趣的模拟题, 需要通过全排列来暴力枚举所有可能的方向映射, 考察了代码的组织和模拟能力.
-E 题 (`lab_4_1163`, 古老的蜘蛛牌): 用 `n <= 300,000` 的数据规模, 将一个看似简单的模拟题, 变成了对栈+贪心 `O(n)` 解法的硬性考察.
-
-### 👹 问题 F (`lab_4_1164`) & G (`lab_4_1165`): 复杂度的终极考验
-
-这两道题是本次实验的"劝退"核心, 它们不仅要求最优的时间复杂度, 还对代码实现和性能细节提出了极高要求.
-
-F 题 (矩阵表达式求值):
-
-这是本次实验最"阴险"的题目. 它将两个复杂的知识点 (中缀表达式求值 + 矩阵运算) 结合在一起. 学生不仅要写对双栈算法, 还要正确实现矩阵的各种运算.
-
-`submit.csv` 中惊人的提交次数 (2841次) 和海量的 RE/PE/WA
-
-G 题 (最小/最大栈):
-
-`n <= 400,000` 的操作次数, 要求在每次 `pop` 后 O(1) 返回栈内最大减最小值. 这是一道考察"最小/最大栈" (使用辅助栈) 的模板题.
-
-它不仅考察了特定的数据结构设计, 还因为海量数据和 Java 的装箱/拆箱性能问题, 给学生上了关于底层性能优化的深刻一课.
-
----
-
-## 总结性批判
-
-难度设计断层严重: 从基础的字符串和栈应用, 直接跳跃到需要双指针、贪心、高级数据结构设计 (如最小/最大栈) 和复杂模拟的难题, 中间缺少了足够的过渡.
-
-过于强调"竞赛思维": 整套题目的设计思路, 尤其是对时间复杂度的极致压榨, 完全是算法竞赛 (ACM/ICPC) 的风格. 这对于旨在培养大多数学生基本编程素养的常规课程来说, 目标可能出现了偏差.
-
-考察范围过广: 一次实验同时考察了字符串、栈、队列、表达式求值、矩阵、贪心、双指针、高级数据结构设计等大量知识点, 并且要求极高的实现精度, 这对学生的消化和吸收能力是巨大的挑战.
-
----
-
-## 结论
-
-> 这套题目作为选拔性测试是极其成功的, 它能精准地筛选出那些具有算法天赋、思维缜密、基础扎实的学生.
->
-> 但作为一次面向全体学生的'教学', 它在引导和启发方面的作用是负面的. 可能会打击大部分学生的学习热情, 而非激发他们的兴趣.
diff --git a/2018fall/lab_4/lab_4_1039/README.md b/2018fall/lab_4/lab_4_1039/README.md
deleted file mode 100644
index f5954df..0000000
--- a/2018fall/lab_4/lab_4_1039/README.md
+++ /dev/null
@@ -1,69 +0,0 @@
-## Description
-
-There are n brackets. And you want to know whether they are match to each other.
-
-The brackets will only contain `{` `}` `(` `)` `[` `]`.
-
-The matching rules are the same as in Math.
-
-For example, `{{[}]}` is not matching, and `[{{}}()]` is matching.
-
-Please write a program to check whether the given brackets string is matching or not.
-
-### Input
-
-The first line will be an integer T, which is the number of test cases. (1 <= T <= 10)
-
-For each test case, the first line will be an integer n ( 1 <= n <= 30000)
-
-Then there is a line with n brackets.
-
-### Output
-
-For each test case, print `YES` if the test case is a matching case. Otherwise, print `NO`.
-
-### Sample Input
-
-```log
-7
-1
-(
-2
-()
-2
-{]
-6
-[(){}]
-4
-(])[
-8
-[[{{}}]]
-6
-[][{]]
-```
-
-### Sample Output
-
-``` log
-NO
-YES
-NO
-YES
-NO
-YES
-NO
-```
-
-## 解答
-
-这道题就是经典的括号匹配问题, 属于数据结构课程的入门必刷题.
-
-解决思路非常直接: 使用一个栈(在 Java 里我们用更现代的 `Deque` 实现). 遍历输入的括号字符串:
-- 遇到开括号(`{`, `[`, `(`), 就把它压进栈里.
-- 遇到闭括号(`}`, `]`, `)`), 就从栈顶取出一个开括号来配对. 如果栈是空的, 或者取出的开括号不匹配, 那这个字符串肯定就不可行了.
- - 注意不要一个字符一个字符的读, 然后读到一半就break, 这会导致后续数据乱掉.
- - 如果不允许引用数据结构, 请先实现一个Stack, 然后用这个Stack来实现
-
-
-遍历完整个字符串后, 如果栈正好是空的, 说明所有括号都完美配对, 输出 "YES"; 否则就是 "NO".
-
diff --git a/2018fall/lab_4/lab_4_1039/pom.xml b/2018fall/lab_4/lab_4_1039/pom.xml
deleted file mode 100644
index f003f06..0000000
--- a/2018fall/lab_4/lab_4_1039/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
-
- nanoseeds.algorithm-template.2018fall
- lab_4
- ${revision}
- ./../pom.xml
-
- nanoseeds.algorithm-template.2018fall.lab4
- lab_4_1039
- ${revision}
- ${project.groupId}.${project.artifactId}
- ${project.groupId}.${project.artifactId}
-
-
- ${project.basedir}/src
- ${project.basedir}/test
-
-
diff --git a/2018fall/lab_4/lab_4_1039/resources/01.data.in b/2018fall/lab_4/lab_4_1039/resources/01.data.in
deleted file mode 100644
index c3bf301..0000000
--- a/2018fall/lab_4/lab_4_1039/resources/01.data.in
+++ /dev/null
@@ -1,15 +0,0 @@
-7
-1
-(
-2
-()
-2
-{]
-6
-[(){}]
-4
-(])[
-8
-[[{{}}]]
-6
-[][{]]
diff --git a/2018fall/lab_4/lab_4_1039/resources/01.data.out b/2018fall/lab_4/lab_4_1039/resources/01.data.out
deleted file mode 100644
index 8e8f811..0000000
--- a/2018fall/lab_4/lab_4_1039/resources/01.data.out
+++ /dev/null
@@ -1,7 +0,0 @@
-NO
-YES
-NO
-YES
-NO
-YES
-NO
diff --git a/2018fall/lab_4/lab_4_1039/src/Main.java b/2018fall/lab_4/lab_4_1039/src/Main.java
deleted file mode 100644
index b63cfaf..0000000
--- a/2018fall/lab_4/lab_4_1039/src/Main.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.List;
-import java.util.StringTokenizer;
-
-public final class Main {
-
- public static List reader() {
- final var input = new Reader();
- final int testcases = input.nextInt();
- assert testcases >= 1 && testcases <= 10 : "T must be between 1 and 10";
- final List cases = new ArrayList<>(testcases);
- for (int i = 0; i < testcases; i++) {
- int n = input.nextInt();
- final String s = input.next();
- assert s.length() == n : "n should be equal to the length of the string";
- assert n >= 1 && n <= 30000 : "n must be between 1 and 30000";
- assert s.matches("[\\{\\}\\[\\]\\(\\)]+") : "String must contain only brackets";
- cases.add(s);
- }
- return cases;
- }
-
- public static List cal(List inputs) {
- final List results = new ArrayList<>();
- for (String s : inputs) {
- if (isBalanced(s)) {
- results.add("YES");
- } else {
- results.add("NO");
- }
- }
- return results;
- }
-
- private static boolean isBalanced(String s) {
- final Deque stack = new ArrayDeque<>();
- for (char c : s.toCharArray()) {
- if (c == '(' || c == '{' || c == '[') {
- stack.push(c);
- } else {
- if (stack.isEmpty()) {
- return false;
- }
- char top = stack.pop();
- if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) {
- return false;
- }
- }
- }
- return stack.isEmpty();
- }
-
- public static void main(String[] args) {
- final var datas = reader();
- final var result = cal(datas);
- output(result);
- }
-
- public static void output(List decides) {
- for (var decide : decides) {
- System.out.print(decide);
- System.out.print('\n');
- }
- }
-
- // refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
- // url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
- // license: MIT
- private static final class Reader {
- private final BufferedReader br;
- private StringTokenizer st;
-
- private Reader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
-
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
-
- int nextInt() {
- return Integer.parseInt(next());
- }
-
- long nextLong() {
- return Long.parseLong(next());
- }
-
- double nextDouble() {
- return Double.parseDouble(next());
- }
-
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
-}
diff --git a/2018fall/lab_4/lab_4_1039/test/MainTest.java b/2018fall/lab_4/lab_4_1039/test/MainTest.java
deleted file mode 100644
index 91bd0de..0000000
--- a/2018fall/lab_4/lab_4_1039/test/MainTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// SPDX-FileCopyrightText: 2018-2025 nanoseeds
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
-import tests.Pair;
-import tests.Redirect;
-
-
-import java.io.*;
-
-@Slf4j
-public final class MainTest {
- private static final String DATA_PATH = "resources/";
- private static final long begin_time = System.currentTimeMillis();
-
- @AfterAll
- public static void last_one() throws IOException {
- log.info("cost {} ms\n", System.currentTimeMillis() - begin_time);
- }
-
- @BeforeEach
- public void beforeEach(TestInfo testInfo) {
- log.info("{} begin", testInfo.getDisplayName());
- }
-
- @AfterEach
- public void afterEach(TestInfo testInfo) {
- log.info("{} end", testInfo.getDisplayName());
- }
-
- @Test
- public void test_2() throws IOException {
- try (Redirect redirect = Redirect.from(DATA_PATH,"01.data.in", "01.test.out")){
- Main.output(Main.cal(Main.reader()));
- final Pair