hdu 1030 Delta-wave

Posted lucky_少哖

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 1030 Delta-wave相关的知识,希望对你有一定的参考价值。

Delta-wave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7539    Accepted Submission(s): 2914


Problem Description
A triangle field is numbered with successive integers in the way shown on the picture below.



The traveller needs to go from the cell with number M to the cell with number N. The traveller is able to enter the cell through cell edges only, he can not travel from cell to cell through vertices. The number of edges the traveller passes makes the length of the traveller\'s route.

Write the program to determine the length of the shortest route connecting cells with numbers N and M.
 

 

Input
Input contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).
 

 

Output
Output should contain the length of the shortest route.
 

 

Sample Input
6
12
 

 

Sample Output
3
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  1035 1071 1032 1031 1041 
 
很简单的题,弄懂题意,很容易写。
 
题意:求给出的两个数字所在表中的位置的距离。
 
附上代码:
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 using namespace std;
 6 int abs(int a)
 7 {
 8     return a>0?a:-a;
 9 }
10 int main()
11 {
12     int n,m,i,j,cm,cn,rm,rn,lm,ln;
13     while(~scanf("%d%d",&m,&n))
14     {
15         cm=(int)ceil(sqrt(m));//ceil为向上取整函数“math.h”
16         cn=(int)ceil(sqrt(n));
17         rm=(m-(cm-1)*(cm-1)-1)/2+1;
18         rn=(n-(cn-1)*(cn-1)-1)/2+1;
19         lm=(cm*cm-m)/2+1;
20         ln=(cn*cn-n)/2+1;
21         int sum=(int)abs(cm-cn)+abs(rm-rn)+abs(lm-ln);
22         printf("%d\\n",sum);
23     }
24     return 0;
25 }

 

以上是关于hdu 1030 Delta-wave的主要内容,如果未能解决你的问题,请参考以下文章

HDU - 1030 Delta-wave

hdu1030 金字塔平方数求层数 数学题

HDU 1030 数学题

hdu_1030 求先序排列

HDU 5387Clock

解决“错误代码:1030。从存储引擎 MEMORY 收到错误 1“不允许操作””