diff --git a/2018fall/lab_2/lab_2_1133/RAEDME.md b/2018fall/lab_2/lab_2_1133/README.md
similarity index 100%
rename from 2018fall/lab_2/lab_2_1133/RAEDME.md
rename to 2018fall/lab_2/lab_2_1133/README.md
diff --git a/2018fall/lab_2/lab_2_1134/RAEDME.md b/2018fall/lab_2/lab_2_1134/README.md
similarity index 100%
rename from 2018fall/lab_2/lab_2_1134/RAEDME.md
rename to 2018fall/lab_2/lab_2_1134/README.md
diff --git a/2018fall/lab_2/lab_2_1135/RAEDME.md b/2018fall/lab_2/lab_2_1135/README.md
similarity index 100%
rename from 2018fall/lab_2/lab_2_1135/RAEDME.md
rename to 2018fall/lab_2/lab_2_1135/README.md
diff --git a/2018fall/lab_2/lab_2_1136/RAEDME.md b/2018fall/lab_2/lab_2_1136/README.md
similarity index 100%
rename from 2018fall/lab_2/lab_2_1136/RAEDME.md
rename to 2018fall/lab_2/lab_2_1136/README.md
diff --git a/2018fall/lab_3/README.md b/2018fall/lab_3/README.md
new file mode 100644
index 0000000..3274cd6
--- /dev/null
+++ b/2018fall/lab_3/README.md
@@ -0,0 +1,38 @@
+---
+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
new file mode 100644
index 0000000..7afbded
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1138/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..9d6c868
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1138/resources/01.data.in
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 0000000..e6f1167
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1138/resources/01.data.out
@@ -0,0 +1,2 @@
+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
new file mode 100644
index 0000000..aac6424
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1138/src/Main.java
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..988a6eb
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1138/test/MainTest.java
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+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
new file mode 100644
index 0000000..a8b4289
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/README.md
@@ -0,0 +1,7 @@
+---
+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
new file mode 100644
index 0000000..8732acf
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..96f993b
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/resources/01.data.in
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000..7938dcd
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/resources/01.data.out
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..49bbdae
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/src/Main.java
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..022bbc7
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1139/test/MainTest.java
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..2d52b8c
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..e2c6744
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/01.data.in
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 0000000..1d4555e
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/01.data.out
@@ -0,0 +1,2 @@
+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
new file mode 100644
index 0000000..f82a280
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/02.data.in
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 0000000..281fa1f
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/02.data.out
@@ -0,0 +1,2 @@
+-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
new file mode 100644
index 0000000..6b4e9e6
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/03.data.in
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 0000000..aa47d0d
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/resources/03.data.out
@@ -0,0 +1,2 @@
+0
+0
diff --git a/2018fall/lab_3/lab_3_1140/src/Main.java b/2018fall/lab_3/lab_3_1140/src/Main.java
new file mode 100644
index 0000000..a5975bd
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/src/Main.java
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..b72cfac
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1140/test/MainTest.java
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..8a71909
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/README.md
@@ -0,0 +1,62 @@
+---
+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
new file mode 100644
index 0000000..1c3d14a
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..6d13e14
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/resources/01.data.in
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000..0ef5c04
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/resources/01.data.out
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..38470c7
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/src/Main.java
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..022bbc7
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1141/test/MainTest.java
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..84663cc
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/README.md
@@ -0,0 +1,109 @@
+---
+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
new file mode 100644
index 0000000..b2ec5ec
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..d0810f6
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/resources/01.data.in
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..64bb6b7
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/resources/01.data.out
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..72d71c6
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/resources/02.data.in
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..6f4247a
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/resources/02.data.out
@@ -0,0 +1 @@
+26
diff --git a/2018fall/lab_3/lab_3_1142/src/Main.java b/2018fall/lab_3/lab_3_1142/src/Main.java
new file mode 100644
index 0000000..54c364b
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/src/Main.java
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..8dc27c5
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1142/test/MainTest.java
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..afbb028
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/README.md
@@ -0,0 +1,11 @@
+---
+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
new file mode 100644
index 0000000..490064c
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..35360b0
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/resources/01.data.in
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..b85905e
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/resources/01.data.out
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..f6788c0
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/resources/02.data.in
@@ -0,0 +1,3 @@
+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
new file mode 100644
index 0000000..aacd980
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/resources/02.data.out
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000..7332586
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/src/Main.java
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..8dc27c5
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1143/test/MainTest.java
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..35e735d
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/README.md
@@ -0,0 +1,9 @@
+---
+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
new file mode 100644
index 0000000..8cd5c6a
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/pom.xml
@@ -0,0 +1,22 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java.2018fall
+ lab_3
+ ${revision}
+ ./../pom.xml
+
+ nanoseeds.CS203_DSAA_template_java.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
new file mode 100644
index 0000000..eae4c93
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/resources/01.data.in
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 0000000..c6c4143
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/resources/01.data.out
@@ -0,0 +1,2 @@
+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
new file mode 100644
index 0000000..02d89c6
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/src/Main.java
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+/*
+CS203_DSAA_template
+
+Copyright (C) 2023 nanos Certseeds
+*/
+
+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
new file mode 100644
index 0000000..ea59119
--- /dev/null
+++ b/2018fall/lab_3/lab_3_1144/test/MainTest.java
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+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
new file mode 100644
index 0000000..43d0796
--- /dev/null
+++ b/2018fall/lab_3/pom.xml
@@ -0,0 +1,36 @@
+
+
+ 4.0.0
+
+
+ nanoseeds.CS203_DSAA_template_java
+ 2018fall
+ ${revision}
+ ./../pom.xml
+
+ pom
+ nanoseeds.CS203_DSAA_template_java.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.CS203_DSAA_template_java
+ test_include_package
+ ${revision}
+ test
+
+
+
+
diff --git a/2018fall/pom.xml b/2018fall/pom.xml
index 9ae84a5..3dfea9b 100644
--- a/2018fall/pom.xml
+++ b/2018fall/pom.xml
@@ -18,5 +18,6 @@
lab_example
lab_2
+ lab_3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b72fd19..4777183 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,15 @@
+## 0.0.5 (2023-04-27)
+
+* feat: add 2018fall_lab_3 3162888
+* feat: add 2018fall_lab3_1138 9e5d719
+* feat: add 2018fall_lab3_1139 077792c
+* feat: add 2018fall_lab3_1140 1b48074
+* feat: add 2018fall_lab3_1141 ead9632
+* feat: add 2018fall_lab3_1142 da3f552
+* feat: add 2018fall_lab3_1144 7b8711e
+* feat: bump version to 0.0.5-SNAPSHOT b68eef6
+* feat: update 2018fall_lab3_1143 and 2018fall_lab3's conclusion 4df0309
+
## 0.0.4 (2023-04-08)
* feat: add 2018fall_lab2_1129 020ccf6
@@ -6,7 +18,7 @@
* feat: add lab_2_1133 c7f028a
* feat: add lab_2_1135 3d29ddb
* feat: add lab_2_1136 fbba0f6
-* feat: bump version to v0.0.4 6e56a8e
+* feat: bump version to v0.0.4 cf0e125
* feat: bump version to v0.0.4-SNAPSHOT 04ffa81
* feat: precommit import 'set -e, set -u, set -x, set pipefail' 45250ef
* feat: update lab_2_1134 b606f7c
diff --git a/build_tools/resources/template/parent/top.xml b/build_tools/resources/template/parent/top.xml
index e363380..123b4c4 100644
--- a/build_tools/resources/template/parent/top.xml
+++ b/build_tools/resources/template/parent/top.xml
@@ -10,7 +10,7 @@
${project.artifactId}
${project.artifactId}
- 0.0.4
+ 0.0.5
11
3.0.0
5.9.2
diff --git a/package.json b/package.json
index 2bb82af..21529c9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "CS203_DSAA_template_java",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Template for CS203-DSAA Based on OpenJDK11 and Maven Monorepo",
"main": "index.js",
"scripts": {
diff --git a/pom.xml b/pom.xml
index 12e06e1..690e539 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
${project.artifactId}
${project.artifactId}
- 0.0.4
+ 0.0.5
11
3.0.0
5.9.2