HDU1030_Delta-wave_多维坐标
来源:互联网 发布:网络录像机怎么联网 编辑:程序博客网 时间:2024/06/05 11:06
Delta-wave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8610 Accepted Submission(s): 3428
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.
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
如图结构的一个地图,给出两个数字。求从第一个数字移动到第二个数字的最小步数。
大体思路:
可以把图中的每一个格用一个三维坐标表示。最后三维坐标的差值加起来即可。
#include<cstdio>#include<cmath>#include<cstdlib>int main(){int M,N,Mx,My,Mz,Nx,Ny,Nz;while(scanf("%d%d",&M,&N)!=EOF){Mx=sqrt(M-1)+1;My=(M-(Mx-1)*(Mx-1)+1)/2;Mz=(Mx*Mx-M)/2+1;Nx=sqrt(N-1)+1;Ny=(N-(Nx-1)*(Nx-1)+1)/2;Nz=(Nx*Nx-N)/2+1;printf("%d\n",abs(Mx-Nx)+abs(My-Ny)+abs(Mz-Nz));}return 0;}
0 0
- HDU1030_Delta-wave_多维坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 多维数组
- 多维数组
- 多维数组
- 多维数组
- 多维数据库
- 多维数据库
- 多维数据模型
- 多维数组
- C# 6 与 .NET Core 1.0 高级编程
- 实习第一天序
- jQuery-选择器
- MySQL 对于千万级的大表要怎么优化?
- Android 利用二阶贝塞尔曲线自定义弧形动画
- HDU1030_Delta-wave_多维坐标
- Android Studio 更换国内源下载依赖库
- UML之活动图
- 004_java中String的两种赋值方式的区别
- Spring MVC+Maven+Velocity的配置过程
- HDU 2509 Be the Winner(博弈论入门题)
- 关于textarea无法居中的问题
- C#编程基础->XML系列导航
- Leetcode 475 -Heaters(二分 or 贪心)