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.去 ...
随机推荐
- APIO2017游记
铁牌选手爆零滚粗记QAQ........ CCF说不让讨论APIO相关内容不过现在应该没事了吧QAQ day0:上午还在学校填清北夏令营的表,下午上火车去北京,晚上颓颓颓...... day1:上午网 ...
- Recompile Squid with SSL Bump
https://docs.diladele.com/administrator_guide_4_0/system_configuration/https_filtering/recompile_squ ...
- java equals 与 hashCode
转:http://m.blog.csdn.net/blog/pengchua/2297547# 如果你为某个类写了equals方法,那么应该同时编写hashCode方法.如果没有提供hashcode方 ...
- symfony 关于nginx的配置问题
好久没有使用symfony,今天想重新宠幸的时候,却碰到了一个很尴尬的问题,下载安装好symfony的时候访问首页成功安装,然而写了一个其它的路由却怎么都是404. 官网看了n遍的路由配置,什么开始第 ...
- error C4996: ‘Json::Reader::Char’: Use CharReader and CharReaderBuilder instead
1.编译下面代码时,遇到标题中的错误 const char* str = "{\"name\":\"xiaoming\",\"age\&qu ...
- linux select函数详解【转】
转自:http://www.cnblogs.com/ccsccs/articles/4224253.html 在Linux中,我们可以使用select函数实现I/O端口的复用,传递给 select函数 ...
- hdu 1116(并查集+欧拉路径)
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1166.敌兵布阵-完全版线段树(单点增减、区间求和)
生活艰辛,且行且珍惜. 先水一篇博客再去补题,要不然又忘记写博客了. 计划系统的刷一遍线段树专题,自己给自己找虐(自作孽不可活),从基础的到后面的,所有的都挂了题,刷题不,大兄弟? 线段树可真有意思, ...
- 51nod 1007 正整数分组【01背包变形】
1007 正整数分组 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 ...
- Python的并发并行[3] -> 进程[1] -> 多进程的基本使用
多进程的基本使用 1 subprocess 常用函数示例 首先定义一个子进程调用的程序,用于打印一个输出语句,并获取命令行参数 import sys print('Called_Function.py ...