#include <cstdlib>
#include <iostream>
using namespace std;
int potega(int a, int w)
{
if (w==0)
return 1;
if (w%2==0)
{
int b = potega(a,w/2);
return b*b;
}
int b = potega(a,(w-1)/2);
return b*b*a;
}
void wypisz(int tab[], int n)
{
for (int i=0; i<n; i++)
cout<<tab[i]<<" ";
cout<<endl;
}
void odwroc (int tab[], int p, int k)
{
for(int i=p; i<(p+k)/2.0; i++)
{
int tmp=tab[i];
tab[i]=tab[k+p-i];
tab[k+p-i]=tmp;
}
}
void tasuj(int tab[], int p, int k, long long t)
{
if (t%2==0)
wypisz(tab,k);
else
{
odwroc(tab,0,k-1);
wypisz(tab, k);
}
}
int main(int argc, char *argv[])
{
//wczytanie danych:
int n;
long long t;
scanf("%d %d", &n, &t);
long long p=potega(2,n);
int tab[p];
for (long long i=0; i<p; i++)
cin>>tab[i];
//program:
tasuj(tab,0,p,t);
//system("PAUSE");
return EXIT_SUCCESS;
}
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include <cstdlib> #include <iostream> using namespace std; int potega(int a, int w) { if (w==0) return 1; if (w%2==0) { int b = potega(a,w/2); return b*b; } int b = potega(a,(w-1)/2); return b*b*a; } void wypisz(int tab[], int n) { for (int i=0; i<n; i++) cout<<tab[i]<<" "; cout<<endl; } void odwroc (int tab[], int p, int k) { for(int i=p; i<(p+k)/2.0; i++) { int tmp=tab[i]; tab[i]=tab[k+p-i]; tab[k+p-i]=tmp; } } void tasuj(int tab[], int p, int k, long long t) { if (t%2==0) wypisz(tab,k); else { odwroc(tab,0,k-1); wypisz(tab, k); } } int main(int argc, char *argv[]) { //wczytanie danych: int n; long long t; scanf("%d %d", &n, &t); long long p=potega(2,n); int tab[p]; for (long long i=0; i<p; i++) cin>>tab[i]; //program: tasuj(tab,0,p,t); //system("PAUSE"); return EXIT_SUCCESS; } |
English