git reimport

This commit is contained in:
2019-03-15 13:47:54 +04:00
commit 3b461f73de
489 changed files with 1631603 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package chelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import io.InputReader;
import io.OutputWriter;
public class B {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int pol = in.nextInt();
if (pol == 0) {
out.print(-1);
return;
}
List<Chelik> cheliki = new ArrayList<>();
for (int i = 2; i <= n; i++) {
cheliki.add(new Chelik(i, in.nextInt()));
}
Collections.sort(cheliki);
cheliki.add(0, new Chelik(1, pol));
List<String> answer = new ArrayList<>();
int left = 0;
for (int right = 1; right < n; right++) {
if (left == right) {
out.print(-1);
return;
}
if (cheliki.get(left).dzun > 0) {
answer.add(cheliki.get(left).index + " " + cheliki.get(right).index);
cheliki.get(left).dzun--;
} else {
left++;
right--;
}
}
out.println(answer.size());
for (String s : answer) {
out.println(s);
}
}
class Chelik implements Comparable<Chelik> {
int index;
int dzun;
public Chelik(int index, int dzun) {
this.index = index;
this.dzun = dzun;
}
@Override
public int compareTo(Chelik o) {
return Integer.compare(o.dzun, dzun);
}
}
}

View File

@@ -0,0 +1,37 @@
1 B
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
3
0
10
4
1 2 1 0
-1
1
1
13 6
2 0 1 3 2 0
-1
1
2
7 3
0 2 2
-1
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.B
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2017.03.04
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,121 @@
package chelper;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import io.InputReader;
import io.OutputWriter;
public class C {
char[] dirsOrderLabels = {'D', 'L', 'R', 'U'};
int[][] dirsOrder = {
{1, 0}, //D
{0, -1}, //L
{0, 1}, //R
{-1, 0}, //U
};
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
int startX = -1;
int startY = -1;
boolean[][] map = new boolean[n][m];
for (int i = 0; i < n; i++) {
String s = in.nextLine();
for (int j = 0; j < m; j++) {
map[i][j] = s.charAt(j) != '*';
if (s.charAt(j) == 'X') {
startX = i;
startY = j;
}
}
}
int[][] distances = new int[n][m];
for (int i = 0; i < n; i++) {
Arrays.fill(distances[i], Integer.MAX_VALUE);
}
Queue<int[]> queue = new LinkedList<>();
queue.add(new int[]{startX, startY});
distances[startX][startY] = 0;
while (!queue.isEmpty()) {
int[] posAr = queue.poll();
int x = posAr[0];
int y = posAr[1];
for (int[] dir : dirsOrder) {
int xx = x + dir[0];
int yy = y + dir[1];
if (xx < 0 || xx >= n || yy < 0 || yy >= m) {
continue;
}
if (!map[xx][yy]) {
continue;
}
if (distances[xx][yy] <= distances[x][y] + 1) {
continue;
}
distances[xx][yy] = distances[x][y] + 1;
queue.add(new int[]{xx, yy});
}
}
StringBuilder answer = new StringBuilder();
int x = startX;
int y = startY;
int timeLeft = k;
while (timeLeft >= distances[x][y] && timeLeft > 0) {
boolean ok = false;
for (int i = 0; i < 4; i++) {
int[] dir = dirsOrder[i];
int xx = x + dir[0];
int yy = y + dir[1];
if (xx < 0 || xx >= n || yy < 0 || yy >= m) {
continue;
}
if (!map[xx][yy]) {
continue;
}
if (timeLeft == distances[x][y] && distances[xx][yy] >= distances[x][y]) {
continue;
}
ok = true;
x = xx;
y = yy;
timeLeft--;
answer.append(dirsOrderLabels[i]);
break;
}
if (!ok) {
out.println("IMPOSSIBLE");
return;
}
}
if (timeLeft != 0 || x != startX || y != startY) {
out.println("IMPOSSIBLE");
return;
}
out.println(answer);
}
}

View File

@@ -0,0 +1,81 @@
1 C
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
9
0
13 2 3 2
.**
X..
2 RL
1
1
41 5 6 14
..***.
*...X.
..*...
..*.**
....*.
14 DLDDLLLRRRUURU
1
2
17 3 3 4
***
*X*
***
11 IMPOSSIBLE
1
3
13 2 3 4
.**
X..
-1
1
4
29 4 5 5
*****
*X***
*.***
*.***
-1
1
5
11 2 2 1
.X
..
10 IMPOSSIBLE
1
6
11 2 2 4
.X
..
4 DLRU
1
7
7 1 1 2
X
10 IMPOSSIBLE
1
8
9 2 1 2
X
.
2 DU
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.C
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2017.03.04
0
1
14 io.InputReader
15 io.OutputWriter
0
0