这是一道组合数学题:
要想(0,0)到(n,m)一定要是从(1,1),因为从n轴不能经过,因为S(n, 0) = 0,那么从(1,1)到(n,m)横轴要走n-m步,纵轴要走m-1格,由于每次走2格,因此只要走(m-1)/2步;
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #include<cstring> #include<vector> #include<string> #define LL long long using namespace std; int Get_num2( int x ) { if( x == 0 ) return 0; return x/2 + Get_num2( x/2 ); } int main( ) { int n,m,T; while( scanf( "%d",&T )==1 ) { while( T-- ) { scanf( "%d %d" ,&n,&m ); int num2 = Get_num2( n - m + ( m -1 )/2 ) -Get_num2( n - m ) - Get_num2( (m-1)/2 ); if( num2 > 0 ) puts( "0" ); else puts( "1" ); } } //system( "pause" ); return 0; }