afdaf @ 2021-11-21 13:02:27
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define ll long long
#define ull unsigned long long
int read()
{
char ch=getchar();
int x=0,f=1;
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void divv(int k,int x,int y,int lx,int ly)
{
if(k==1)
{
if(x%2==1&&y%2==1) printf("%d %d 1\n",x+1,y+1);
else if (x%2==1&&y%2==0) printf("%d %d 2\n",x+1,y-1);
else if (x%2==0&&y%2==1) printf("%d %d 3\n",x-1,y+1);
else if(x%2==0&&y%2==0) printf("%d %d 4\n",x-1,y-1);
return ;
}
//1<<(k-1)
if(x<=lx&&y<=ly)
{
printf("%d %d 1\n",lx+1,ly+1);
divv(k-1,x,y,lx-(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx+1,ly+1,lx+(1<<(k-2)),ly+(1<<(k-2)));
divv(k-1,lx,ly+1,lx-(1<<(k-2)),ly+(1<<(k-2)));
divv(k-1,lx+1,ly,lx+(1<<(k-2)),ly-(1<<(k-2)));
}
else if(x>lx&&y<=ly)
{
printf("%d %d 3\n",lx,ly+1);
divv(k-1,x,y,lx+(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx,ly,lx-(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx,ly+1,lx-(1<<(k-2)),ly+(1>>(k-2)));
divv(k-1,lx+1,ly+1,lx+(1>>(k-2)),ly+(1>>(k-2)));
}
else if(x<=lx&&y>ly)
{
printf("%d %d 2\n",lx+1,ly);
divv(k-1,x,y,lx-(1<<(k-2)),ly+(1<<(k-2)));
divv(k-1,lx,ly,lx-(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx+1,ly,lx+(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx+1,ly+1,lx+(1<<(k-2)),ly+(1<<(k-2)));
}
else if(x>lx&&y>ly)
{
printf("%d %d 4\n",lx,ly);
divv(k-1,x,y,lx+(1<<(k-2)),ly+(1<<(k-2)));
divv(k-1,lx,ly,lx-(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx+1,ly,lx+(1<<(k-2)),ly-(1<<(k-2)));
divv(k-1,lx,ly+1,lx-(1<<(k-2)),ly+(1<<(k-2)));
}
}
int main ()
{
int k=read();
int x=read(),y=read();
divv (k,x,y,1<<(k-1),1<<(k-1));
}