Skip to content

Commit

Permalink
Merge branch 'develop' into master for release v0.0.5
Browse files Browse the repository at this point in the history
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
  • Loading branch information
Certseeds committed Apr 27, 2023
2 parents aad0bcf + 3735cb8 commit 1ee1f04
Show file tree
Hide file tree
Showing 59 changed files with 2,137 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions 2018fall/lab_3/README.md
Original file line number Diff line number Diff line change
@@ -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上渲染出来.
22 changes: 22 additions & 0 deletions 2018fall/lab_3/lab_3_1138/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>nanoseeds.CS203_DSAA_template_java.2018fall</groupId>
<artifactId>lab_3</artifactId>
<version>${revision}</version>
<relativePath>./../pom.xml</relativePath>
</parent>
<groupId>nanoseeds.CS203_DSAA_template_java.2018fall.lab3</groupId>
<artifactId>lab_3_1138</artifactId>
<version>${revision}</version>
<name>${project.groupId}.${project.artifactId}</name>
<description>${project.groupId}.${project.artifactId}</description>

<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/test</testSourceDirectory>
</build>
</project>
7 changes: 7 additions & 0 deletions 2018fall/lab_3/lab_3_1138/resources/01.data.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
2
4 5
1 2 3 4
1 2 3 4 5
1 3
2
1 3 4
2 changes: 2 additions & 0 deletions 2018fall/lab_3/lab_3_1138/resources/01.data.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 1 2 2 3 3 4 4 5
1 2 3 4
167 changes: 167 additions & 0 deletions 2018fall/lab_3/lab_3_1138/src/Main.java
Original file line number Diff line number Diff line change
@@ -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<Integer> fst;
private final List<Integer> snd;

public one(List<Integer> fst, List<Integer> snd) {
this.fst = fst;
this.snd = snd;
}
}

public static List<one> read() {
final var input = new Scanner(System.in);
final int testcases = input.nextInt();
assert ((1 <= testcases) && (testcases <= 15));
final List<one> 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<Integer> fst = new ArrayList<>(n); // 还想优化这里可以用裸数组
final List<Integer> 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<one> reader() {
final var input = new Reader();
final int testcases = input.nextInt();
assert ((1 <= testcases) && (testcases <= 15));
final List<one> 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<Integer> fst = new ArrayList<>(n);
final List<Integer> 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<List<Integer>> cal(List<one> nums) {
final List<List<Integer>> 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<Integer> 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<List<Integer>> 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;
}
}
}
51 changes: 51 additions & 0 deletions 2018fall/lab_3/lab_3_1138/test/MainTest.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> p = redirect.compare_double("01.data.out", "01.test.out");
Assertions.assertEquals(p.getFirst().length(), p.getSecond().length());
Assertions.assertEquals(p.getFirst(), p.getSecond());
}
}
}
7 changes: 7 additions & 0 deletions 2018fall/lab_3/lab_3_1139/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
SPDX-License-Identifier: CC-BY-NC-SA-4.0
---

# lab_3_1139

难以分析想表达点什么, 这和sort有关系吗?
22 changes: 22 additions & 0 deletions 2018fall/lab_3/lab_3_1139/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>nanoseeds.CS203_DSAA_template_java.2018fall</groupId>
<artifactId>lab_3</artifactId>
<version>${revision}</version>
<relativePath>./../pom.xml</relativePath>
</parent>
<groupId>nanoseeds.CS203_DSAA_template_java.2018fall.lab3</groupId>
<artifactId>lab_3_1139</artifactId>
<version>${revision}</version>
<name>${project.groupId}.${project.artifactId}</name>
<description>${project.groupId}.${project.artifactId}</description>

<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/test</testSourceDirectory>
</build>
</project>
4 changes: 4 additions & 0 deletions 2018fall/lab_3/lab_3_1139/resources/01.data.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2 CBBCJJKZKZ
3 GAKKBDDBAGNN
3 NACCQNDDQAEE
0
3 changes: 3 additions & 0 deletions 2018fall/lab_3/lab_3_1139/resources/01.data.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
1
0
Loading

0 comments on commit 1ee1f04

Please sign in to comment.