You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
typedef long long LL ;
struct Point {
LL x , y ;
} ;
// 功能: 在一个n级的矩阵中, 求标号为a的格子坐标
Point get ( LL n , LL a ) {
if ( n = = 0 ) return { 0 , 0 } ; // 1级是4个, 2级是16个, 3级是64个,0级时只有一个点, 坐标就是(0,0)
LL block = 1ll < < n * 2 - 2 ; // 1个块的大小: 1级1个, 2级4个, 3级16个,也就是4^(n-1)=2^(2n-2)
LL len = 1ll < < n - 1 ; // 1级移动1, 2级移动2,3级移动4,总结: n级2^(n-1)
auto p = get ( n - 1 , a % block ) ; // n-1级时, a这个点的原来对应格子在坐标是什么
LL x = p . x , y = p . y ;
int z = a / block ; // 0~3哪个块
if ( z = = 0 ) return { y , x } ; // y=x对称
if ( z = = 1 ) return { x , y + len } ; // 向右平移len个距离
if ( z = = 2 ) return { x + len , y + len } ; // 向右平移len个距离, 再向下移动len个距离
if ( z = = 3 ) return { len * 2 - 1 - y , len - 1 - x } ; // 关于2^(n-1)-1那条直线对称
}
int main ( ) {
int T ;
scanf ( " %d " , & T ) ;
while ( T - - ) {
LL n , a , b ;
scanf ( " %lld%lld%lld " , & n , & a , & b ) ;
auto pa = get ( n , a - 1 ) ; // 下标从0开始, 方便取模
auto pb = get ( n , b - 1 ) ;
double dx = pa . x - pb . x , dy = pa . y - pb . y ;
printf ( " %.0lf \n " , sqrt ( dx * dx + dy * dy ) * 10 ) ;
}
return 0 ;
}