http://acm.hdu.edu.cn/showproblem.php?pid=3766

Knight's Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 482    Accepted Submission(s): 106

Problem Description
In chess, each move of a knight consists of moving by two squares horizontally and one square vertically, or by one square horizontally and two squares vertically. A knight making one move from location (0,0) of an infinite chess board would end up at one of the following eight locations: (1,2), (-1,2), (1,-2), (-1,-2), (2,1), (-2,1), (2,-1), (-2,-1).

Starting from location (0,0), what is the minimum number of moves required for a knight to get to some other arbitrary location (x,y)?

 
Input
Each line of input contains two integers x and y, each with absolute value at most one billion. The integers designate a location (x,y) on the infinite chess board. The final line contains the word END.
 
Output
For each location in the input, output a line containing one integer, the minimum number of moves required for a knight to move from (0,0) to (x, y).
 
Sample Input
1 2、
2 4
END
 
Sample Output
1
2
/**
首先,xy的大小排序和转化为都是正数步数不变应该懂吧。
y=2*x这种情况直接就是(x+y)/3步。
如果y<2*x但是(x+y)%3==0的话,那么我们可以通过控制(1,2),(2,1)
两种跳法的次数达到...总数必然是(x+y)/3,然后xy的和对3取余是1的话,
我们是不是必然可以在(x+y-1)/3步的时候跳到(x,y-1)这个点,但是不能一步
跳到(x,y),回撤两步到(x-4,y-5)这个点,我们可以用三步跳到(x,y),那么
就是原先的步数+1。余数为2,就是先跳到(x-1,y-1)这个地方,我们知道(0,0)
到(1,1)只需要两步,那么(x-1,y-1)到(x,y)也就是原先步数+2.然后考虑y>2*x,
先把(0,1)的情况特殊处理一下。接着我们可以用x步跳到(x,y),那么原问题就
转化为(0,0)到(0,y-2*x)。当y-2*x是4的倍数的话我们可以直接(1,2)(-1,2)这个
跳可以在(y-2*x)/2步到达。余数为1,就是(0,0)到(0,1)的问题,但是这个需要
三步不是最优的,我们后撤两步变为(0,0)到(0,5),我们可以三步达到,那么就
是原先的步数加上1就是解。余数为2,我们可以分别跳一次(2,1)(-2,1)到达。
余数为3,转化为(0,0)到(0,3)的问题我们可以(-1,2)(1,1)(0,3)三步到达。
以上就是全部情况,o(╯□╰)o,在纸上画画,应该所有在这这几类范围内。
**/ #include<stdio.h>
#include<string.h>
int main()
{
char c[]; while(scanf("%s", c), strcmp(c, "END"))
{
int x, y;
int k; sscanf(c, "%d", &x);
scanf("%d", &y); if(x<) x = -x;
if(y<) y = -y; if(y<x) {k=x, x=y, y=k;}
if(y<=*x)
{
if(x== && y==)
printf("2\n");
else if(x== && y==)
printf("4\n");
else
printf("%d\n", (x+y)/+(x+y)%);
}
else
{
int ans = x;
int c=(y-*x)%; ans += c;
ans += (y-*x-c)/; if(y== && x==)
ans = ; printf("%d\n", ans);
}
}
return ;
}

(数学)Knight's Trip -- hdu -- 3766的更多相关文章

  1. [ACM_数学] 大菲波数 (hdu oj 1715 ,java 大数)

    大菲波数 Problem Description Fibonacci数列,定义如下:f(1)=f(2)=1f(n)=f(n-1)+f(n-2) n>=3.计算第n项Fibonacci数值.   ...

  2. 数学(GCD,计数原理)HDU 5656 CA Loves GCD

    CA Loves GCD Accepts: 135 Submissions: 586 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 2621 ...

  3. Ant Trip HDU - 3018(欧拉路的个数 + 并查集)

    题意: Ant Tony和他的朋友们想游览蚂蚁国各地. 给你蚂蚁国的N个点和M条边,现在问你至少要几笔才能所有边都画一遍.(一笔画的时候笔不离开纸) 保证这M条边都不同且不会存在同一点的自环边. 也就 ...

  4. Day4 - K - Ant Trip HDU - 3018

    Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together with his fr ...

  5. 2018年暑假ACM个人训练题7 题解报告

    A:HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用) B:(还需要研究一下.....) C:HDU 1071 The area(求三个点确定的抛物线的面积, ...

  6. hdu 2425 Hiking Trip

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2425 Hiking Trip Description Hiking in the mountains ...

  7. 【数学】HDU 5761 Rower Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5761 题目大意: 船在(0,a),船速v1,水速v2沿x轴正向,船头始终指向(0,0),问到达(0, ...

  8. 【数学】HDU 5753 Permutation Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 题目大意: 两个序列h和c,h为1~n的乱序.h[0]=h[n+1]=0,[A]表示A为真则为 ...

  9. 【规律】【贪心】【数学】HDU 5573 Binary Tree

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5573 题目大意: 从1走到第k层,下一层的数是上一层的数*2或者*2+1,可以选择加上或者减去走的数 ...

随机推荐

  1. oracle:the password has expired

    今天在用dbvisualizer登录数据库的时候,报了the password has expired的错误,于是上网查了一下原因,是因为数据库密码过期了,因为默认的是180天. 解决方法: 1)用系 ...

  2. Luogu 1641[SCOI2010]生成字符串 - 卡特兰数

    Description 有$N$ 个 $1$ 和 $M$ 个 $0$ 组成的字符串, 满足前 $k$ 个字符中 $1$ 的个数不少于 $0$ 的个数. 求这样字符串的个数. $1<=M < ...

  3. Vim中如何使用正则进行搜索

    #set magic这句的作用在于将vim的正则打开. 这样就可以搜索了. 至于正则的相关的内容.在此抄一份.以免于下次自己还要去百度. 符号 匹配 . (dot) 任意单一字符 \d 任意一位数字 ...

  4. Spring IOC(三)单例 bean 的注册管理

    Spring IOC(三)单例 bean 的注册管理 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 在 Spring 中 ...

  5. Python3实战系列之二(获取印度售后数据项目)

    问题:续接上一篇.说干咱就干呀,勤勤恳恳写程序呀! 目标:安装python和pycharm.要编写并运行python程序就需要电脑有开发工具和运行环境,所以此篇就是安装编辑和运行python程序的软件 ...

  6. maven打包之后为什么class文件中没有注释了?

    <!--生成doc jar包--> <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...

  7. centos配置虚拟用户再也不用那么麻烦了

    http://wiki.centos.org/HowTos/Chroot_Vsftpd_with_non-system_users yum install -y vsftpd db4-utils vs ...

  8. SQL将完整时间字段截取到年月日

    在SQL查询语句中使用convert(char(10),日期字段,120)方法 1.char(10)指'yyyy-mm-dd'正好10个字符 2.120的是日期的格式 3.使用语句:select * ...

  9. Redis的基操

    redis:通常BOLEAN操作类型,操作成功返回1,操作失败返回0 通常如果往设置的key插入值,但是这个key不存在,redis则会创建 向redis里的某个key插入多个值时,值和值之间用空格隔 ...

  10. [网络]10M、100M、1000M网线的水晶头接法

    在网络维护过程中经常要自己制作网线,水晶头理论上是这样接的: 10M和100M和1000M以太网在使用网线时,对网线各自有不同的要求. 10M和100M在目前来说,连接网络的时候,只用到两对线来传输网 ...