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 ;
int w , m , n ;
/*
测试用例:
6 8 2
答案: 4
*/
//计算点的行号
int row ( int i ) {
if ( i % w = = 0 ) //值是宽度的倍数
return i / w ;
else //值不是宽度的倍数
return i / w + 1 ;
}
//计算点的列号
int col ( int i ) {
if ( row ( i ) % 2 = = 0 ) { //该值在偶数行
if ( i % w = = 0 ) // 找规律可知,偶数行能被整除肯定在第一列
return 1 ;
//在偶数行(从大到小)但不能被整除, 在倒数第j%w列, 即正数第w-j%w+1列
return w - i % w + 1 ;
} else { //在奇数行
if ( i % w = = 0 ) return w ; //找规律可知,偶数行能被整除肯定在最后一列
return i % w ; //在奇数行(从小到大)但不能被整除, 在第j%w列
}
}
int main ( ) {
cin > > w > > m > > n ;
int s = abs ( row ( n ) - row ( m ) ) + abs ( col ( n ) - col ( m ) ) ;
printf ( " %d \n " , s ) ;
return 0 ;
}