HDU 1030 Delta-wave
来源:互联网 发布:电信网通网络转换器 编辑:程序博客网 时间:2024/06/10 17:24
Delta-wave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9343 Accepted Submission(s): 3734
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>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))// { cm=(int)ceil(sqrt(m));//C主层次 cn=(int)ceil(sqrt(n)); rm=(m-(cm-1)*(cm-1)-1)/2+1; //R右层次 rn=(n-(cn-1)*(cn-1)-1)/2+1; lm=(cm*cm-m)/2+1; //L左层次 ln=(cn*cn-n)/2+1; int cnt=(int)(fabs(cm-cn)+fabs(lm-ln)+fabs(rm-rn)); printf("%d\n",cnt); } return 0;}
阅读全文
1 0
- HDU 1030 Delta-wave
- HDU 1030 Delta-wave
- HDU 1030 Delta-wave
- HDU-1030-Delta-wave
- hdu 1030 Delta-wave
- hdu 1030 Delta-wave
- hdu 1030 Delta-Wave+
- HDU 1030 Delta-wave
- Hdu 1030 Delta Wave
- hdu 1030 Delta-wave
- Delta-wave(HDU 1030)
- hdu 1030 Delta-wave
- hdu 1030 Delta-wave
- HDU 1030 Delta-wave
- hdu 1030 Delta-wave
- 【HDU】 1030 Delta-wave
- hdu 1030 Delta-wave
- hdu 1030 Delta-wave
- BloomFilter应用与D-Lelft BloomFilter实现
- 在控制台中输入msqyl一直报ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost'错误
- HDU3829Cat VS Dog(二分图最大独立集)
- 思维导图,带你走进《西游记》人物的世界
- Hadoop集群安装配置
- HDU 1030 Delta-wave
- 《深入理解java虚拟机》读书笔记三 【回收对象和方法区】
- HTML之表格标签及属性
- G
- nginx的安装
- 数学之美番外篇:平凡而又神奇的贝叶斯方法
- linux 开机启动流程
- 求质数算法的N种境界[1]
- 【HDU1492】The number of divisors(约数) about Humble Numbers