Delta-wave

HDU - 1030

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.

InputInput contains two integer numbers M and N in the range from 1 to 1000000000 separated with space(s).OutputOutput should contain the length of the shortest route.Sample Input

6 12 

Sample Output

3

OJ-ID: 
hdu-1030 author:
Caution_X date of submission:
20191010 tags:
规律题 description modelling:
给定图,问两个数字之间的“距离” major steps to solve it:
将给定图分为3个图,两个数字之间的距离就是两个数字分别在3个图中的距离之和 warnings: AC Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,m;
while(~scanf("%lld%lld",&n,&m)) {
ll cn,cm,ln,lm,rn,rm;
cn=ceil(sqrt(n));
cm=ceil(sqrt(m));
lm=(m-(cm-)*(cm-)-)/+;
ln=(n-(cn-)*(cn-)-)/+;
rm=(cm*cm-m)/+;
rn=(cn*cn-n)/+;
ll ans=;
ans=abs(cn-cm)+abs(ln-lm)+abs(rn-rm);
printf("%lld\n",ans);
}
return ;
}

Delta-wave HDU - 1030的更多相关文章

  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. hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏

    problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...

  5. hdu 1030 Delta-wave(数学题+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1030 Delta-wave Time Limit: 2000/1000 MS (Java/Others ...

  6. hdu 1030 Delta-wave

    Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. HDU 1030 Delta-wave 数学题解

    给出一个数字塔,然后求沿着数字之间的边走,给出两个数字,问其路径最短的长度是多少. 看似一条搜索题目,只是有一定做题经验的人都知道,这个不是搜索题,直接搜索肯定超时. 这个是依据规律计算的数学题目. ...

  8. HDU 1030(三角数阵 数学)

    题意是问在给定的三角形数阵中从一个数到另一个数所要跨过的边数. 最初的时候很迷,除了发现每层的数字个数与层数间的关系和每层数最后一个数与层数的关系外什么也没看出来,打算先求出数字所在的层数,然后计算到 ...

  9. HDU 1030 数学题

    给出两点,求这两点在图上的最短路径 分别以最上,左下,右下为顶点,看这个三角图形 ans=这三种情况下两点的层数差 #include "stdio.h" #include &quo ...

随机推荐

  1. CRF keras代码实现

    这份代码来自于苏剑林 # -*- coding:utf-8 -*- from keras.layers import Layer import keras.backend as K class CRF ...

  2. php捕获Fatal error错误与异常处理

    php中的错误和异常是两个不同的概念. 错误:是因为脚本的问题,比如少写了分号,调用未定义的函数,除0,等一些编译语法错误. 异常:是因为业务逻辑和流程,不符合预期情况,比如验证请求参数,不通过就用 ...

  3. SQLserver创建用户和给用户权限(学)

    数据库基础知识:http://blog.csdn.net/u014600432/article/details/39645701 在SQL Server中创建用户角色及授权(使用SQL语句):http ...

  4. Oracle 中Number的长度定义

    Number可以通过如下格式来指定:Field_NAME Number(precision ,scale),其中precision指Number可以存储的最大数字长度(不包括左右两边的0),scale ...

  5. H5 移动端 键盘遮挡焦点元素解决方案

    前言 最近在做 webapp,遇到了很多移动端兼容的问题,其中一个问题就是:输入框触发 focus 后,键盘弹出,然后遮住了输入框. 然后在Android和IOS上,这个问题的表现形式不一样,而原生键 ...

  6. 执行插件的替代方式:用JS调用操作

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复229或者20161028可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  7. WC 个人项目 ( node.js 实现 )

    基于 node.js 的 wordCounter 个人项目 GitHub 项目地址:https://github.com/KofeChen/node.js-WordCounter 实现功能: 能够匹配 ...

  8. 生成前N个自然数随机置换的3个程序

    问题描述: 假设需要生成前N个自然数的一个随机置换.例如,{4,3,1,5,2}和{3,1,4,2,5}就是合法的置换,但{5,4,1,2,1}却不是,因为数1出现两次而数3却没有.这个程序常常用于模 ...

  9. 渗透测试学习 二十一、 JSP相关漏洞

    大纲 ST2漏洞  (Struts2) 反序列漏洞              网站容器,中间键 其他漏洞 Struts2漏洞 简介: Struts2是一个基于MVC设计模式的Web应用框架,它本质上相 ...

  10. 如何下载Youtube上的视频, 字幕, MP3等资源, 方法简单直接!

    Youtube不用多说了吧,秒杀国内一众视频平台,没有之一, 既然关注Youtube说明大家对Youtube都是认同的.不用说4K,8K视频,比起国内一些伪4K, 真的良心, 就连广告也是5秒跳过, ...