hdu1030——Delta-wave
来源:互联网 发布:深度linux桌面 编辑:程序博客网 时间:2024/05/21 14:43
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<stdio.h>#include<math.h>void find(int n,int &l,int &r,int &level){ int i; level=1; for(i=1;;i+=2) { if(n-i<=0) { l=(n+1)/2; r=(i-n)/2+1; break; } level++; n-=i; }}int main(){ int m,n; int ml,mr,nl,nr,mlevel,nlevel; while(scanf("%d%d",&m,&n)!=EOF) { find(m,ml,mr,mlevel); find(n,nl,nr,nlevel); printf("%d\n",abs(ml-nl)+abs(mr-nr)+abs(mlevel-nlevel)); } return 0;}
0 0
- hdu1030——Delta-wave
- ACM-简单题之Delta-wave——hdu1030
- hdu1030-Delta-wave
- hdu1030 - Delta-wave
- HDU1030 Delta-wave
- HDU1030 Delta-wave(java)
- HDU1030 Delta-wave(找规律)
- HDU1030 - Delta-wave (找规律)
- hdu1030 - Delta-wave (三角洲数学水题)
- 数学—杭电1030 Delta-wave
- 杭电OJ——1030 Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- LeetCode ---Remove Duplicates from Sorted Array
- js 图片上传前浏览
- 两个栈实现一个队列
- 业务流程图2
- 最小重量机器设计问题——优先队列式分支限界法
- hdu1030——Delta-wave
- MySQL5.5半同步复制配置安装
- 计算摄影学论文集锦
- 在ATS 5.3.0上测试域名统计插件channel_stats
- 彩色图像,二值图像,灰度图像,不要傻傻分不清~
- 【团队分享】iOS8.3给发图带来的坑,怎样迅速填平?
- LeetCode ---Remove Element
- Mat与Iplimage之间的相互转换
- 选择主键:自然键还是代理键?