git reimport
This commit is contained in:
231
archive/2019.02/2019.02.21 - unsorted/D.java
Normal file
231
archive/2019.02/2019.02.21 - unsorted/D.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class D extends SimpleSavingChelperSolution {
|
||||
|
||||
public static final int N = 100000;
|
||||
public static final int TOTAL_TURNS = 100;
|
||||
public static final int PREP_TURNS = 45;
|
||||
|
||||
static class Solver {
|
||||
List<Integer> history = new ArrayList<>();
|
||||
int minIndex = -1;
|
||||
int turn = 0;
|
||||
|
||||
String decide(String s) {
|
||||
int x = -1;
|
||||
if (s != null) {
|
||||
x = strToInt(s);
|
||||
}
|
||||
|
||||
int ans = decide(x, turn);
|
||||
turn++;
|
||||
return intToStr(ans);
|
||||
}
|
||||
|
||||
int decide(int x, int turn) {
|
||||
if (turn == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
history.add(x);
|
||||
|
||||
if (turn < PREP_TURNS) {
|
||||
return x;
|
||||
}
|
||||
|
||||
if (turn == PREP_TURNS) {
|
||||
findMinIndex();
|
||||
System.err.println("GUESS:");
|
||||
System.err.println("max: " + intToStr(history.get(minIndex - 1)));
|
||||
System.err.println("min: " + intToStr(history.get(minIndex)));
|
||||
}
|
||||
|
||||
int maxValue = history.get(minIndex - 1);
|
||||
int minValue = history.get(minIndex);
|
||||
int randValue = history.get(minIndex + 1);
|
||||
|
||||
if (x == maxValue) {
|
||||
return minValue;
|
||||
}
|
||||
if (x == minValue) {
|
||||
return randValue;
|
||||
}
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
void findMinIndex() {
|
||||
for (int i = 1; i < history.size() - 1; i++) {
|
||||
for (int j = i + 1; j < history.size() - 1; j++) {
|
||||
for (int k = j + 1; k < history.size() - 1; k++) {
|
||||
int a1 = history.get(i - 1);
|
||||
int a2 = history.get(i);
|
||||
int a3 = history.get(i + 1);
|
||||
int b1 = history.get(j - 1);
|
||||
int b2 = history.get(j);
|
||||
int b3 = history.get(j + 1);
|
||||
int c1 = history.get(k - 1);
|
||||
int c2 = history.get(k);
|
||||
int c3 = history.get(k + 1);
|
||||
|
||||
if (a1 == b1 && b1 == c1
|
||||
&& a2 == b2 && b2 == c2
|
||||
&& a1 != a2
|
||||
&& a3 != b3 && a3 != c3 && b3 != c3
|
||||
) {
|
||||
minIndex = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < history.size() - 1; i++) {
|
||||
for (int j = i + 1; j < history.size() - 1; j++) {
|
||||
int a1 = history.get(i - 1);
|
||||
int a2 = history.get(i);
|
||||
int a3 = history.get(i + 1);
|
||||
int b1 = history.get(j - 1);
|
||||
int b2 = history.get(j);
|
||||
int b3 = history.get(j + 1);
|
||||
|
||||
if (a1 == b1
|
||||
&& a2 == b2
|
||||
&& a1 != a2
|
||||
&& a3 != b3
|
||||
) {
|
||||
minIndex = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(":(");
|
||||
}
|
||||
}
|
||||
|
||||
static class Checker {
|
||||
List<String> bank = new ArrayList<>();
|
||||
Map<String, Integer> bankPos = new HashMap<>();
|
||||
Random random = new Random();
|
||||
|
||||
Checker() {
|
||||
for (int i = 0; i < N; i++) {
|
||||
bank.add(intToStr(i));
|
||||
}
|
||||
Collections.shuffle(bank, random);
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
bankPos.put(bank.get(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
boolean greater(String a, String b) {
|
||||
if (a.equals(bank.get(0)) && b.equals(bank.get(N - 1))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return bankPos.get(a) > bankPos.get(b);
|
||||
}
|
||||
|
||||
String decide(String s) {
|
||||
int x = bankPos.get(s);
|
||||
|
||||
if (x == N - 1) {
|
||||
return bank.get(0);
|
||||
}
|
||||
|
||||
if (x == 0) {
|
||||
return bank.get(x + 1 + random.nextInt(N - x - 2));
|
||||
}
|
||||
|
||||
return bank.get(x + 1 + random.nextInt(N - x - 1));
|
||||
}
|
||||
|
||||
int run() {
|
||||
Solver solver = new Solver();
|
||||
int score = 0;
|
||||
|
||||
String prev = null;
|
||||
for (int i = 0; i <= TOTAL_TURNS; i++) {
|
||||
String attempt = solver.decide(prev);
|
||||
|
||||
if (prev != null && greater(attempt, prev)) {
|
||||
score++;
|
||||
}
|
||||
|
||||
prev = decide(attempt);
|
||||
|
||||
if (!greater(prev, attempt)) {
|
||||
System.err.println("WAHT");
|
||||
}
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
public void solve(int testNumber) {
|
||||
int T = in.nextInt();
|
||||
int N = in.nextInt();
|
||||
|
||||
for (int i = 0; i < T; i++) {
|
||||
solveTestCase();
|
||||
}
|
||||
}
|
||||
|
||||
static int strToInt(String s) {
|
||||
int result = 0;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
result *= 10;
|
||||
result += s.charAt(i) - 'A';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static String intToStr(int x) {
|
||||
String result = "";
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
result = (char) (x % 10 + 'A') + result;
|
||||
x /= 10;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void solveTestCase() {
|
||||
// Checker checker = new Checker();
|
||||
// System.err.println(checker.run());
|
||||
|
||||
Solver solver = new Solver();
|
||||
String prev = null;
|
||||
for (int i = 0; i <= TOTAL_TURNS; i++) {
|
||||
String answer = solver.decide(prev);
|
||||
System.out.println(answer);
|
||||
System.out.flush();
|
||||
|
||||
if (i < TOTAL_TURNS) {
|
||||
prev = in.nextString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
archive/2019.02/2019.02.21 - unsorted/D.json
Normal file
33
archive/2019.02/2019.02.21 - unsorted/D.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name" : "D",
|
||||
"testType" : "SINGLE",
|
||||
"input" : {
|
||||
"type" : "STANDARD",
|
||||
"fileName" : "input.txt"
|
||||
},
|
||||
"output" : {
|
||||
"type" : "STANDARD",
|
||||
"fileName" : "output.txt"
|
||||
},
|
||||
"tests" : [ {
|
||||
"input" : "1 5",
|
||||
"index" : 0,
|
||||
"active" : true
|
||||
} ],
|
||||
"location" : "src/chelper",
|
||||
"vmArgs" : "-Xmx256m -Xss64m",
|
||||
"mainClass" : "Main",
|
||||
"taskClass" : "chelper.D",
|
||||
"checkerClass" : "net.egork.chelper.checkers.TokenChecker",
|
||||
"checkerParameters" : "",
|
||||
"testClasses" : [ ],
|
||||
"date" : "2019.02.21",
|
||||
"contestName" : "",
|
||||
"truncate" : true,
|
||||
"inputClass" : "io.InputReader",
|
||||
"outputClass" : "io.OutputWriter",
|
||||
"includeLocale" : false,
|
||||
"failOnOverflow" : false,
|
||||
"interactive" : false,
|
||||
"interactor" : "net.egork.chelper.tester.Interactor"
|
||||
}
|
Reference in New Issue
Block a user