hdu 1030 Delta-wave(数学题+找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1030
Delta-wave

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.
6 12
3
pid=1027" target="_blank">1027
1031 1041watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">另外一种是左斜着的列号:
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int abs(int a)
{
if (a>0)
return a;
else
return -a;
} int main()
{
int a,b;
while (~scanf("%d%d",&a,&b))
{
int h1=sqrt(a);
if (h1*h1==a)
h1=h1;
else
h1=h1+1;
int h2=sqrt(b);
if (h2*h2==b)
h2=h2;
else
h2=h2+1;
int r1=h1*h1;
int rx1=(r1-a)/2+1;
int r2=h2*h2;
int rx2=(r2-b)/2+1;
int l1=r1-(2*h1-1)+1;
int lx1=(a-l1)/2+1;
int l2=r2-(2*h2-1)+1;
int lx2=(b-l2)/2+1;
int ans=abs(h1-h2)+abs(lx1-lx2)+abs(rx1-rx2);
cout<<ans<<endl;
}
return 0;
}
hdu 1030 Delta-wave(数学题+找规律)的更多相关文章
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- HDU 4910 Problem about GCD 找规律+大素数判断+分解因子
Problem about GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4572 Bottles Arrangement(找规律,仔细读题)
题目 //找规律,123321123321123321…发现这样排列恰好可以错开 // 其中注意题中数据范围: M是行,N是列,3 <= N < 2×M //则猜测:m,m,m-1,m-1 ...
- HDU 1041 Computer Transformation(找规律加大数乘)
主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<t ...
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 1391 number steps(找规律,数学)
Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown ...
- HDU 4731 Minimum palindrome (找规律)
M=1:aaaaaaaa…… M=2:DFS+manacher, 暴出N=1~25的最优解,找规律.N<=8的时候直接输出,N>8时,头两个字母一定是aa,剩下的以aababb循环,最后剩 ...
- HDU 4662 MU Puzzle(找规律)
题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去 ...
随机推荐
- error : cannot open source file "SDKDDKVer.h"
属性->VC++ Directions-> include path 中加了:$(IncludePath) library path 中加了:$(LibraryPath)
- Vitamio 视频播放
资料总结 Vitamio官网:https://www.vitamio.org 源码地址:https://github.com/yixia/VitamioBundle 最佳教程:大名鼎鼎的农民伯伯博客 ...
- WCF技术解剖2-TcpTracer路由解析代码
TcpTrace路由解析,参考页面-http://www.cnblogs.com/artech/archive/2008/09/19/1294227.html. TcpTrace工具下载地址:http ...
- linux下修改mysql数据库编码后无法启动解决办法
linux下老版本的Mysql修改数据库编码的方法是 修改my.cnf vi /etc/my.cnf 在[client]下添加 default-character-set=utf8 在[mysqld] ...
- xen 不同后端存储方案的性能对比
概述 在xen平台下,一般使用文件来模拟一个磁盘.在xen中使用文件来模拟磁盘有3种方式, blkback 直接操作 blktap2 直接将文件映射为一个裸块设备,这样vm可以直接用phy的方式进行文 ...
- Selenium2+python自动化13-多窗口、句柄(handle)【转载】
前言 有些页面的链接打开后,会重新打开一个窗口,对于这种情况,想在新页面上操作,就得先切换窗口了.获取窗口的唯一标识用句柄表示,所以只需要切换句柄,我们就能在多个页面上灵活自如的操作了. 一.认识多窗 ...
- python 实现经典算法
import time start_time = time.clock() list_ = [9, 2, 7, 4, 5, 6, 3, 8, 1] """ # 堆排序(通 ...
- sql:将秒转化成时分秒格式
DECLARE @a int=20000 SELECT CONVERT(VARCHAR(10),@a/60)+'分'+CONVERT(VARCHAR(10),@a%60)+'秒' --333分20秒 ...
- [BZOJ1260][CQOI2007]涂色paint 区间dp
1260: [CQOI2007]涂色paint Time Limit: 30 Sec Memory Limit: 64 MB Submit: 1575 Solved: 955 [Submit][S ...
- 网盘+SVN
1.安装网盘 选择一个国内有名的网盘存储,例如金山网盘.360云盘等,注册账户会默认赠送几G的使用空间,然后下载其对应的网盘客户端管理软件(也可以使用浏览器方式),使用账号登录,就可以上传.管理文件等 ...