Delta-wave HDU - 1030
时间:2019-10-10
本文章向大家介绍Delta-wave HDU - 1030,主要包括Delta-wave HDU - 1030使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
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.
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 12Sample 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-1)*(cm-1)-1)/2+1; ln=(n-(cn-1)*(cn-1)-1)/2+1; rm=(cm*cm-m)/2+1; rn=(cn*cn-n)/2+1; ll ans=0; ans=abs(cn-cm)+abs(ln-lm)+abs(rn-rm); printf("%lld\n",ans); } return 0; }
原文地址:https://www.cnblogs.com/cautx/p/11651121.html
- 从WordPress SQLi谈PHP格式化字符串问题
- 自己实现PC端jQuery版轮播图
- Tips for thrift
- Java8新特性——StreamAPI(一)
- springcloud学习手册-Hystrix(仪表盘说明)
- RedRabbit——基于BrokerPattern服务器框架
- C++任务队列与多线程
- 游戏服务器ID生成器组件
- Java8新特性——Lambda表达式(一)
- C++ FFLIB之FFRPC:多线程&多进程的scalability探索
- ffrpc-c++进程间(服务器端、客户端)通信框架
- Docker入门实战(一)——Docker常用命令
- C++使用ffpython嵌入和扩展python
- 前端防御从入门到弃坑——CSP变迁
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Typescript 设计模式之工厂方法
- vue中获取外网IP的方法
- WPF图片处理相关
- WPF文件压缩
- 如何实现SAP WebClient UI附件批量上传
- Python基础教程
- 使用Source Monitor检测Java代码的环复杂度
- 使用Source Monitor检测Java代码的环复杂度
- AndroidStdio1_2
- 使用扩展技术对SAP Fiori应用进行端到端的增强,一个实际案例介绍
- python Unhandled exception in event loop:错误解决
- SAP Fiori image的显示原理
- 解决Error:All flavors must now belong to a named flavor dimension.
- 同时搞定Android和iOS的Dart语言(3):数值类型
- SAP Fiori图标(icon)设计原理