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. git打pach包

    在开发中,我们发出的基线版本号常常会有一些bug须要修复,假设採用本地上库,然后再给用户新的版本号,可能会费时费力,而假设给用户我们改动后的代码让用户一行一行合入本地,也显的比較落后,假设用户那边也使 ...

  2. Calendar 对象的使用实例

    1.Calendar demo例子 JavaCalendar 类时间操作,示范代码. public class CalendarDemo { private static SimpleDateForm ...

  3. Linux文件实时同步,可实现一对多

    说明:该功能服务端安装sersync2,客户端安装rsync,原理就是服务端主动推送设定目录下的所有更新的文件到各个客户端rsync接收. rsync大家都知道,是Linux自带的数据同步工具,而se ...

  4. iOS开发-舒尔特表

    周末闲来无事,看一个概念,挺有意思的,舒尔特表,网上也有很多人写过类似的Demo,本人闲来无事也写了一下,舒尔特表听起来很高大上的样子,不过本人的理解就是一个正方形的矩阵中放的各种小格子,可以是字母, ...

  5. Longest Valid Parentheses leetcode java

    题目: Given a string containing just the characters '(' and ')', find the length of the longest valid ...

  6. JavaScript初学者建议:不要去管浏览器兼容

    如果可以回到过去的话,我会告诉自己这句话:"初学JavaScript的时候无视DOM和BOM的兼容性" 我初学时的处境 在我初学JavaScript的时候最头痛的就是浏览器兼容问题 ...

  7. 向第一个 p 元素添加一个类

    This is a heading This is a paragraph. This is another paragraph. 向第一个 p 元素添加一个类 111 <html> &l ...

  8. TotalCommander使用方法,如何对图片批量重命名

    1 文件或文件夹重命名 F2 2 计算所有文件夹的大小 A/t+Shift+Enter.(这样对于文件的更新操作就更加快捷有效了,比如我的文档里面只有若干个子文件夹有更新,则别的都不用动,只要修改那些 ...

  9. Java从零开始学八(循环结构)

    一.循环结构 循环结构则是根据判断条件的成立与否,决定程序段落的执行次数,而这个程序段落就称为循环主体.

  10. Memcache and Mongodb

    转自:http://www.cnblogs.com/lovecindywang/archive/2010/05/19/1739025.html 先说说自己对Memcache和Mongodb的一些看法. ...