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.去 ...
随机推荐
- POJ1679 The Unique MST
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26782 Accepted: 9598 Description Give ...
- input 输入框提示信息
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Linux Mint---shutter截图软件
shutter 可以说是linux下最好的截图软件了,默认安装好后不能编辑截图,解决方法如下: 1-关闭shutter 2-sudo apt-get install shutter libgoo-ca ...
- mysql服务性能优化—my.cnf_my.ini配置说明详解(16G内存)
这配置已经优化的不错了,如果你的mysql没有什么特殊情况的话,可以直接使用该配置参数 MYSQL服务器my.cnf配置文档详解硬件:内存16G [client]port = 3306socket = ...
- 杭电oj2028、2034、2035、2041、2043-2046
2028 Lowest Common Multiple Plus #include<stdio.h> int gcd(int a,int b){ int temp,temp1; if(a ...
- Inline Hook
@author: dlive IAT Hook时如果要钩取的API不在IAT中(LoadLibrary后调用),则无法使用该技术.而Inline Hook不存在这个限制. 0x01 Inline Ho ...
- (转)MSI - Enable MSI Logging
转自: http://www.cnblogs.com/atempcode/archive/2007/04/10/707917.html 安装MSI安装包的时候, 有时会遇到错误, 这时LOG文件就非常 ...
- wav格式
转自: http://www.cnblogs.com/tiandsp/archive/2012/10/17/2728585.html 起始地址 占用空间 本地址数字的含义 00H 4byte RIFF ...
- xCode中去除“Implicit declaration of function 'sysctl' is invalid in C99” 警告
http://blog.csdn.net/dreambegin/article/details/8609121 一般出现该问题是因为通过C调用了unix/linux 底层接口,所以需要调整c语言的编译 ...
- python里如何计算大文件的md5
在python3中,有了一个hashlib,可以用来计算md5,这里先给出一个简单的例子: import hashlib sstr="i love hanyu" print(has ...