Pagini recente » Profil antonio.salaru | Borderou de evaluare (job #298045) | Cod sursa (job #1626877) | Cod sursa (job #10536) | Cod sursa (job #1987175)
#include <cstdio>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
const int MAXN = 3e6;
#define BUF_SIZE 4096
int v[2 * MAXN + 1], sol[2 * MAXN + 1];
char buf[BUF_SIZE];
int pos = BUF_SIZE;
inline char getChar(FILE *f) {
if (pos == BUF_SIZE) {
fread(buf, 1, BUF_SIZE, f);
pos = 0;
}
return buf[pos++];
}
inline int read(FILE *f) {
int result = 0;
char c;
do {
c = getChar(f);
} while (!isdigit(c));
do {
result = 10 * result + c - '0';
c = getChar(f);
} while (isdigit(c));
return result;
}
void swap(int &a, int &b) {
a ^= b;
b = a ^ b;
a ^= b;
}
int main() {
srand(time(NULL));
int n, s, m;
FILE *f = fopen("congr.in", "r");
n = read(f);
s = 0;
for (int i = 0; i < 2 * n - 1; ++i) {
v[i] = read(f);
if (i <= n) {
s += v[i];
}
sol[i] = i;
}
fclose(f);
m = n - 1;
while (s & m) {
int x = 1 + rand() % n;
int y = n + rand() % n;
if (y == n) {
++y;
}
s -= v[x] + v[y];
swap(v[x], v[y]);
swap(sol[x], sol[y]);
}
f = fopen("congr.out", "w");
for (int i = 0; i < n; ++i) {
fprintf(f, "%d ", sol[i]);
}
fprintf(f, "\n");
fclose(f);
return 0;
}