Delta-wave
来源:互联网 发布:淘宝原创衣服怎么弄 编辑:程序博客网 时间:2024/05/17 23:17
Delta-wave
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.
Write the program to determine the length of the shortest route connecting cells with numbers N and M.
6 12
3
简单数学题,找规律,找到了就发现很水。
从三个角度看这个图,level,left,right,如下图,题目的答案就是3个图上2个点之间的层数的高度差之和。
例如 6 12 ,level=1,left=1,right=1,答案就是3。
例如 3 12 ,level=2,left=1,right=2,答案就是6。
#include<stdio.h>#include<math.h>using namespace std;int main(){ int m,n,cm,cn,rm,rn,lm,ln; //c表示level图 ,r表示right图,l表示left图 while(scanf("%d%d",&m,&n)!=EOF)// { cm=(int)ceil(sqrt(m));//ceil为向上取整函数“math.h” cn=(int)ceil(sqrt(n)); rm=(m-(cm-1)*(cm-1)-1)/2+1; //确定m在right图中的那一层 rn=(n-(cn-1)*(cn-1)-1)/2+1; lm=(cm*cm-m)/2+1; //确定m在left图中的那一层 ln=(cn*cn-n)/2+1; int cnt=(int)(fabs(cm-cn)+fabs(lm-ln)+fabs(rm-rn)); printf("%d\n",cnt); } return 0;}
0 0
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- HDU3723 Delta Wave
- HDU 1030 Delta-wave
- HDU 1030 Delta-wave
- HDU 1030 Delta-wave
- hdu 3723 Delta Wave
- HDU-1030-Delta-wave
- hdu1030-Delta-wave
- hdu 1030 Delta-wave
- HDU 3723 Delta Wave
- hdu 1030 Delta-wave
- hdu 1030 Delta-Wave+
- 【安卓逆向】如何用ida动态调试so文件
- Android 源码解析
- spring事务转账案例
- 从 Qt 的 delete 说开来
- 四、关于自定义view的文章:折线图进阶(触摸版)
- Delta-wave
- 快速排序
- Linux下用ssh连接的方法
- SDK Manager目录解释
- python中math模块的使用
- 携程是如何把大数据用于实时风控的
- ADM2483的原理图
- Python, file readline() method
- 2017.3.12 分割矩阵 失败总结