git reimport
This commit is contained in:
84
archive/2018.02/2018.02.18 - unsorted/B.java
Normal file
84
archive/2018.02/2018.02.18 - unsorted/B.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class B extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
int[][] a = new int[2 * n][n];
|
||||
|
||||
for (int i = 0; i < 2 * n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
a[i][j] = in.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
int p1 = -1;
|
||||
int p2 = -1;
|
||||
|
||||
for (int i = 0; i < 2 * n; i++) {
|
||||
for (int j = i + 1; j < 2 * n; j++) {
|
||||
if (a[i][0] == a[j][0]) {
|
||||
p1 = i;
|
||||
p2 = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[][] res = new int[n][n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
res[0][i] = a[p1][i];
|
||||
res[i][0] = a[p2][i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2 * n; i++) {
|
||||
if (i == p1 || i == p2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int p = -1;
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (res[0][j] == a[i][0]) {
|
||||
p = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (p >= 0) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
res[j][p] = a[i][j];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (res[j][0] == a[i][0]) {
|
||||
p = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
res[p][j] = a[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
out.print(res[i][j] + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user