hdu1030-Delta-wave

来源:互联网 发布:7723java游戏 编辑:程序博客网 时间:2024/05/17 02:03

http://acm.hdu.edu.cn/showproblem.php?pid=1030

数学题,确定层数差 a1 ,还有左差(从三角形的左边排列看属于第几层的差)b1 ,右差c1;

最后求和即可

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std ;int main(){int n , m ;while( cin >> n >> m ){if( n == 0 && m == 0 )break ;int cenn = ( int ) ceil( sqrt( n ) ) ;int cenm = ( int ) ceil( sqrt( m ) ) ;int rn = ( ( n - ( cenn - 1 ) * ( cenn - 1 ) - 1) / 2 + 1 ) ;int rm = ( ( m - ( cenm - 1 ) * ( cenm - 1 ) - 1) / 2 + 1 ) ;int ln = ( cenn * cenn - n ) / 2 + 1 ;int lm = ( cenm * cenm - m ) / 2 + 1 ;int ans = abs( cenn - cenm ) + abs( rn - rm ) + abs( ln - lm ) ;cout << ans << endl ;}return 0 ;}


原创粉丝点击