-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
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开始, 但是计数0开始记到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个. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_1141</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
3 4 0 | ||
3 4 1 | ||
3 3 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Yes | ||
No | ||
Yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<one> read() { | ||
final var input = new Scanner(System.in); | ||
final int testcases = input.nextInt(); | ||
assert ((1 <= testcases) && (testcases <= 100)); | ||
final List<one> 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<one> reader() { | ||
final var input = new Reader(); | ||
final int testcases = input.nextInt(); | ||
assert ((1 <= testcases) && (testcases <= 100)); | ||
final List<one> 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<Boolean> cal(List<one> nums) { | ||
final List<Boolean> 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<Boolean> 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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters