Delta-wave问题:c++
来源:互联网 发布:linux下c语言删除文件 编辑:程序博客网 时间:2024/06/12 12:00
【问题描述】
一个三角形字段用下图所示的连续整数编号。
旅行者需要从m号的细胞到N号的细胞,旅行者只能通过细胞边缘进入细胞,不能通过顶点从细胞到细胞。边缘的旅行次数使得旅行者的路径的长度。
编写程序,确定连接n和m的最短路径的长度。
输入包含两个整数m和n,在1到1000000000之间用空格隔开。
【输出】
输出应包含最短路径的长度。
【输入输出样例】
in
6 12
out
3
【源程序清单】
#include<iostream>#include<cmath>#include <cstdio>#include <cstdlib>using namespace std; int calculate_x(int n) //该数所在层 { return (ceil(sqrt(n))); } int calculate_y(int n, int x) //该数所在右列 { return(n - (x - 1)*(x - 1) + 1) / 2; } int calculate_z(int n, int x) //该数所在左列 { return (x*x - n) / 2 + 1; } int main() { int n, m, x1, x2, y1, y2, z1, z2, sum; while (scanf_s("%d%d", &n, &m)!=EOF) { x1 = calculate_x(n); y1 = calculate_y(n, x1); z1 = calculate_z(n, x1); x2= calculate_x(m); y2=calculate_y(m, x2); z2 = calculate_z(m, x2); sum = abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2); //以三维坐标形式表示出来并进行计算 printf("%d\n", sum); } return 0;}
阅读全文
0 0
- Delta-wave问题:c++
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- Delta-wave
- hdu 1030 Delta-wave (C++, 0ms, explanatory comments.)
- 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
- 音视频专家成长道路
- (零)angular2----online
- (数据结构)非比较排序-计数排序、基数排序的分析与实现
- IntelliJ IDEA 2017 下载和破解方法
- 【Scikit-Learn 中文文档】模型持久化
- Delta-wave问题:c++
- git常用命令总结
- 数据库主键不连续
- ride自动化测试运行第二遍时下方log不显示的问题
- DJjava批量反编译class文件
- 阿里RocketMQ消息队列与Spring整合+Xml配置
- Mac使用经验分享
- 数据结构实验之图论二:图的深度遍历
- 【Android学习】消息机制Handler