#include <cstdio> #include <algorithm> using namespace std; #define MAX_N 1048576 int T[MAX_N]; int main() { int t, n, i; scanf("%d%d", &n, &t); int kon = 1 << n; for (i = 0; i < kon; i++) { scanf("%d", &T[i]); } int mid = kon >> 1; sort(T, T + mid); sort(T + mid, T + kon); if (t & 1) { for (i = kon-1; i >= 0; i--) printf("%d ", T[i]); } else { for (i = mid-1; i >= 0; i--) printf("%d ", T[i]); for (i = kon-1; i >= mid; i--) printf("%d ", T[i]); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <cstdio> #include <algorithm> using namespace std; #define MAX_N 1048576 int T[MAX_N]; int main() { int t, n, i; scanf("%d%d", &n, &t); int kon = 1 << n; for (i = 0; i < kon; i++) { scanf("%d", &T[i]); } int mid = kon >> 1; sort(T, T + mid); sort(T + mid, T + kon); if (t & 1) { for (i = kon-1; i >= 0; i--) printf("%d ", T[i]); } else { for (i = mid-1; i >= 0; i--) printf("%d ", T[i]); for (i = kon-1; i >= mid; i--) printf("%d ", T[i]); } return 0; } |