Hdu 1030 Delta Wave
来源:互联网 发布:淘宝产品怎么排名靠前 编辑:程序博客网 时间:2024/06/10 03:56
Delta-wave
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5770 Accepted Submission(s): 2197
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
题目大意: 已经很清楚了, 就是给你两个数 m , n 要你计算出 m 到 n 的步数
解题方法:分别 计算 在数 M ,N 到顶部 到 左边 到 右边的距离
然后计算M N之间的距 只需要 他们顶部 到左边, 到右边的距离差的绝对值 之和 就是M N之间的距离
代码:
#include<iostream>#include<cmath>#include<cstdio>#include<cstdlib>using namespace std;struct node{ int x, y, z; //x 为到顶部的距离 y 为到左边的距离 z 为到右边的距离};node ssd(int k){ int x = sqrt(k-1.0); //这其实是求上一层的 int y = (k-x*x-1)/2; int z =((x+1)*(x+1)-k)/2; node t; t.x = x; t.y = y; t.z = z; return t;}int main(){ int n , m; while(scanf("%d%d", &n, &m)!= EOF) { //题目大意 输入两个数 A B,这两个数是三角形里面的, 问 A到B的最短路 // 第i行的第 1 个数是 (i-1)^2 + 1 最后一个数是 i^2 //给出m , n 那么他么分别在 ceil(sqrt(n))层 //要求最短距离思路是 到上的层数 到左边的层数, 到右边的层数 之和就是所求 node s, g; s = ssd(n); g = ssd(m); printf("%d\n", abs(s.x-g.x)+ abs(s.y-g.y) + abs(s.z -g.z)); } return 0;}
0 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
- 如果通过优化来提高SEO的效果
- 第七周项目二 求圆柱体的表面积和体积
- 是什么决定着seo的成败?
- 优质外链资源如何获得
- 深信服笔试题(网络工程师售后)
- Hdu 1030 Delta Wave
- SEO优化应该照用户的需求去做
- 基于内容的图像检索技术(2)
- 更新Anadroid SDK Tooks之后,Eclipse提示No update were found
- apache配置双向ssl认证(笔记)
- 任意有根树的左孩子右兄弟表示法存储
- CSDN 世界杯上的ACM
- C++文件读取(fstream和FILE)
- Android入门:ContentProvider