HDU---1030-Delta-wave (简单数学)
来源:互联网 发布:java写入word文件 编辑:程序博客网 时间:2024/05/21 10:59
Delta-wave
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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
Source
Ural Collegiate Programming Contest 1998
<pre name="code" class="cpp">#include <iostream>#include <cmath>#include <cstdio>#include <iomanip>using namespace std;int main(){ int a,b; // 10亿 while(cin>>a>>b) { if(a>b)swap(a,b); int sum; int x=pow((double)(a-1),0.5)+1; // 顶部当前行 int y=pow((double)(b-1),0.5)+1; // 底部当前行 if(x==y) { cout<<b-a<<endl; continue; } int ylen = y-x; //行差 int xx=a-(x-1)*(x-1); //当前坐标 int yy=b-(y-1)*(y-1); //当前坐标 int sum1,sum2; if((xx%2==1 && yy<=xx+2*ylen && yy>=xx) || (xx%2==0 && yy<=xx+2*ylen+1 && yy>=xx-1)) //内部覆盖判断 { sum=2*ylen; if(yy%2==0)--sum; // 底部倒三角 if(xx%2==1)--sum; // 顶部正三角 } else // 外部 { if(xx%2==0) //顶部倒三角 { if(yy<xx-1) //覆盖区域左边 sum=xx-1-yy+2*ylen; else sum=yy-xx-1; //右边 } else //顶部正三角 { if(yy<xx) //覆盖区域左边 sum=xx-yy+2*ylen-1; else sum=yy-xx-1; //右边 } } cout<<sum+1<<endl; } 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
- 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
- linux 命令系列之 进程管理,终止进程(70)
- eclipse各种配置
- C# 窗体抖动
- 虚拟机中Linux克隆后相关配置
- 黑马程序员——GUI(图形用户界面)
- HDU---1030-Delta-wave (简单数学)
- android Menu详解 onCreateOptionsMenu()
- 【linux学习笔记之一】linux系统目录结构以及常用系统命令
- MySQL 用户权限详细汇总
- const详解
- 穆勒五法——因果关系
- XCode中添加第三方库报错Parse Issue: Expected unqualified-id错误的原因
- [ACM学习心得]关于sync_with_stdio(false);
- Apache Zeppelin安装及介绍