Delta-wave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4684    Accepted Submission(s): 1777

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. 
 
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
 
 
 
 
思路:

比如6 16 向右移一格..经过两条边即可...然后将其分层,确定他们的行列来计算相应的值即可。。哎呀,说不清了..
来看代码ba!。。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int sum(int m,int &cc)
{ int rr=(int)sqrt(1.0*m); //确定她所在第几行..一右边为参数
if(rr*rr!=m) rr++;
cc=rr*rr-m;
if(cc&)
return *(rr-);
else
return *rr-;
} int main()
{
int n,m,ncc,mcc,add;
while(cin>>m>>n)
{
int rankn=sum(n,ncc); //得到n的所在第几行
int rankm=sum(m,mcc); //得到m的所在第几行
ncc>>=; //得到n所在第几列,以右边为参数
mcc>>=; //得到m所在第几列,以右边为参数
//此处可以进一步优化...现在就不优化了..
if(rankn==rankm)
cout<<abs(n-m)<<endl;
else
if(rankn<rankm)
{ if(mcc>=ncc&&mcc<=(rankm-rankn)/+ncc)
cout<<(rankm-rankn)<<endl;
else
{ if(*mcc<(rankm-rankn)/+*ncc)
{
add=ncc-mcc;
cout<<*add+(rankm-rankn)<<endl;
}
else
{
add=mcc-((rankm-rankn)/+ncc);
cout<<*add+(rankm-rankn)<<endl;
} }
}
else
{
//rankn>rankm
if(ncc>=mcc&&ncc<=(rankn-rankm)/+mcc)
cout<<(rankn-rankm)<<endl;
else
{
if(*ncc<(rankn-rankm)/+*mcc)
{
add=mcc-ncc;
cout<<*add+(rankn-rankm)<<endl;
}
else
{
add=ncc-((rankn-rankm)/+mcc);
cout<<*add+rankn-rankm<<endl;
}
}
}
/* cout<<0&1<<endl;*/
} return ;
}

HDUOJ----(1030)Delta-wave的更多相关文章

  1. uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

    option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...

  2. HDU3723 Delta Wave —— 卡特兰数

    题目链接:https://vjudge.net/problem/HDU-3723 Delta Wave Time Limit: 6000/3000 MS (Java/Others)    Memory ...

  3. HDU 3723 Delta Wave (高精度+calelan数)

    题意:给定一个图,问你只能向上向下,或者平着走,有多少种方法可以走到最后一个格. 析:首先先考虑,如果没有平的情况就是calelan数了,现在有平的情况,那么就枚举呗,因为数很大,所以要用高精度. 答 ...

  4. RIFF和WAVE音频文件格式

    RIFF file format RIFF全称为资源互换文件格式(Resources Interchange File Format),是Windows下大部分多媒体文件遵循的一种文件结构.RIFF文 ...

  5. BZOJ 1030: [JSOI2007]文本生成器 [AC自动机 DP]

    1030: [JSOI2007]文本生成器 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3953  Solved: 1614[Submit][Stat ...

  6. IEEE 802.11p (WAVE,Wireless Access in the Vehicular Environment)

    IEEE 802.11p(又称WAVE,Wireless Access in the Vehicular Environment)是一个由IEEE 802.11标准扩充的通讯协定.这个通讯协定主要用在 ...

  7. Wave - 花たん 音乐

    Wave 歌手:花たん 所属专辑:Flower 間違えて宇宙終わって(宇宙因为一个错误而终结了) 青信号はいつも通り(通行的灯号一如往常的) 飛んでまた止まって(又再停止传播) また 飛びそうだ(然后 ...

  8. Dirac Delta Function

    也称为Degenerate pdf, 退化概率密度函数. 未经考证的解释是: 当正态分布的\(\sigma \to 0\)时, 正态分布就退化为这个分布了. 定义 \[ \delta(x) = \be ...

  9. PAT A 1030. Travel Plan (30)【最短路径】

    https://www.patest.cn/contests/pat-a-practise/1030 找最短路,如果有多条找最小消耗的,相当于找两次最短路,可以直接dfs,数据小不会超时. #incl ...

  10. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

随机推荐

  1. word排版汇总

    1.iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf 的文档,而且可以将XML.Html文件转化为PDF ...

  2. Objective-C:OC内部可变对象和不可变对象的深(复制)拷贝问题思考:

    OC内部:可变对象和不可变对象的深(复制)拷贝问题思考:   不可变对象:  例如NSString对象,因为NSString对象是常量字符串,所以,不可以更改其内容,但是可以修改指向该字符串的指针指向 ...

  3. 【转】QT CEF3 消息循环处理

    初次写博客,可能有点乱, 按照自己的实际经历谈一下CEF3钟遇到的一些坑,希望对以后的小伙有些帮助. 先说一下经历,当初第一次接触CEF3的时候,没做特殊处理,直接将cef3封装成控件,嵌入到QT程序 ...

  4. jquery json实现二级动态联动

    以下为代码!需要导入json架包 function getCity1(){ var unitid = document.getElementById('addformunitid').value; $ ...

  5. UVA 156 (13.08.04)

     Ananagrams  Most crossword puzzle fans are used to anagrams--groupsof words with the same letters i ...

  6. 你应该知道的30个jQuery代码开发技巧

    1. 创建一个嵌套的过滤器 .filter(":not(:has(.selected))") //去掉所有不包含class为.selected的元素 2. 重用你的元素查询 var ...

  7. document.execCommand("BackgroundImageCache",false,true)解决ie6下的背景图片缓存问题

    E6下的背景图片每次使用都会重新发送请求(not 本地),连一个hover效果时候同样的背景图片仅仅位置不同而已,ie6都会再次发送请求,这个令人崩溃的事情需要解决掉:对于ie来说,filter:ex ...

  8. .NET反射 Type类

    不知道大家有过这样类似的编码 ? 1 Type type=typeof(T);//T是传入的类型 这样写已经是在潜意思的使用反射了.不管你是否知道,但是这是事实. Type是一个抽象类,必须进行实例化 ...

  9. POJ 1564 Sum It Up (DFS+剪枝)

                                                                                                       ...

  10. GeSHi Documentation

    GeSHi Documentation Version 1.0.8.11 Authors: © 2004 - 2007 Nigel McNie © 2007 - 2012 Benny Baumann ...