#include<stdio.h> #include<stdlib.h> #define MAX_LENGTH 1048576 //2^20 int powOf2(int n) { int result = 1; int i; for (i=0; i<n; ++i) { result *= 2; } return result; } int main() { int* deck; int* current_deck; int i, n, t, cards_number; int from, to, diff; deck = malloc(MAX_LENGTH * sizeof(int)); scanf("%d %d\n", &n, &t); cards_number = powOf2(n); //printf("%d", cards_number); current_deck = deck; for (i=0; i<cards_number; ++i) { scanf("%d", current_deck); ++current_deck; } if (t%2) { //odd from = cards_number - 1; to = 0; diff = -1; } else { //even from = 0; to = cards_number -1; diff = 1; } for (i=from; i!=to; i+=diff) { printf("%d ", deck[i]); } printf("%d\n", deck[to]); 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<stdio.h> #include<stdlib.h> #define MAX_LENGTH 1048576 //2^20 int powOf2(int n) { int result = 1; int i; for (i=0; i<n; ++i) { result *= 2; } return result; } int main() { int* deck; int* current_deck; int i, n, t, cards_number; int from, to, diff; deck = malloc(MAX_LENGTH * sizeof(int)); scanf("%d %d\n", &n, &t); cards_number = powOf2(n); //printf("%d", cards_number); current_deck = deck; for (i=0; i<cards_number; ++i) { scanf("%d", current_deck); ++current_deck; } if (t%2) { //odd from = cards_number - 1; to = 0; diff = -1; } else { //even from = 0; to = cards_number -1; diff = 1; } for (i=from; i!=to; i+=diff) { printf("%d ", deck[i]); } printf("%d\n", deck[to]); return 0; } |