Poj Solution 1710

http://poj.org/problem?id=1710

#include<iostream>
#include"memory.h"
using namespace std;
int n;

bool map[101][101];

void init()
{int i,j;bool k;
k=1;
for(i=1;i<=n;i++,k=!k)
map[i][1]=k;

for(i=1;i<=n;i++)
for(j=2;j<=n;j++)
map[i][j]=!map[i][j-1];
}

void doit()
{int i,j,step=2*n+1;bool k=true;

for(i=1;i<n;i++)
{cout<<step;
for(j=1;j<=n;j++)
if(map[i][j]==k)cout<<' '<<(i-1)*n+j;
cout<<endl;
step+=2;k=!k;
cout<<step;
for(j=1;j<=n;j++)
if(map[i][j]==k)cout<<' '<<(i-1)*n+j;
cout<<endl;
step+=2;k=!k;
}

if(n%2)
{for(i=1;i<n;i++,step+=2)
cout<<step<<' '<<(n-1)*n+i<<endl;}
else 
for(i=n;i>1;i--,step+=2)
cout<<step<<' '<<(n-1)*n+i<<endl;

}


int main()
{int t;
//cin>>t;
//while(t--)
{cin>>n;
init();
doit();
//cout<<endl;
}
return 0;
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *