Poj Solution 1430

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

#include<iostream>
using namespace std;

const long big=1024*1024*1024;
long b;
long n,m;
char a[16][34]={
". . . . . . . . . . . . . . . 1",
". . . . . . . . . . . . . 1 1 .",
". . . . . . . . . . . 1 1 1 . .",
". . . . . . . . . 1 1 . 1 . . .",
". . . . . . . 1 1 1 . 1 . . . .",
". . . . . 1 1 . 1 1 1 . . . . .",
". . . 1 1 1 . . 1 1 . . . . . .",
". 1 1 . 1 . . . 1 . . . . . . .",
"1 1 . 1 . . . 1 . . . . . . . .",
"1 1 1 . . 1 1 . . . . . . . . .",
"1 1 . 1 1 1 . . . . . . . . . .",
"1 1 1 . 1 . . . . . . . . . . .",
"1 1 . 1 . . . . . . . . . . . .",
"1 1 1 . . . . . . . . . . . . .",
"1 1 . . . . . . . . . . . . . .",
"1 . . . . . . . . . . . . . . ."};


int find()
{if(m>n)return 0;
b=big;
while(1)
{
if(m<=16&&n<=m/2+8){if(a[16-n][(m-1)*2]=='1')return 1;else return 0;}

while(b/2>=m&&n<=m/2+b/4)b/=2;

if(m>b/2){m-=b/2;n-=b/4;continue;}
if(n>=b/4+m){n-=b/4;continue;}
return 0;
}
return 0;
}


int main()
{int t;
cin>>t;
while(t--)
{cin>>n>>m;
cout<<find()<<endl;
}


return 0;
}
											
This entry was posted in poj. Bookmark the permalink.