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. c#dev tabcontrol 与嵌套gridcontrol 总结

    Gridcontrol设置 1: 拖进去的时候别拖到tabcontrol外边, 否则dock 停靠的时候,停靠错了地方. 2:去掉Drag a column header here to group. ...

  2. Vs2015 c# 诊断工具查看程序的占用情况

    windbg用着还不熟悉,dottrace  还要版权,着急查看程序的cpu 的使用情况,因为程序开启之后占用处理器资源较大,问题在哪里呢,于是点开了vs2015自带的诊断工具,以前偶尔打开过,没发现 ...

  3. 学习javascript怎么入门,初学者5条建议

    你是否已经初步掌握了html和css,但完全不知道从何入手Java?如果是,这里总结了5条建议,帮助JavaScript初学者总结学习方法,提高学习效率. 一.多看视频少看书 对初学者而言,看书的效率 ...

  4. Liunx 重定向,管道符(转)

    原作网址:http://blog.csdn.net/qq_16811963/article/details/52997178 输出重定向 >代表以覆盖的方式将命令的正确输出输出到指定的文件或设备 ...

  5. L1-030 一帮一(15)(代码)

    L1-030 一帮一(15 分) "一帮一学习小组"是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组.本题就请你编写程序帮助老师自动完成这个分配工 ...

  6. HDU_2136

    #include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> ...

  7. Luogu 2216[HAOI2007]理想的正方形 - 单调队列

    Solution 二维单调队列, 这个数组套起来看得我眼瞎... Code #include<cstdio> #include<algorithm> #include<c ...

  8. Telnet远程登录

    假设 电脑A Telnet远程登录 电脑B (Windows) 1.电脑B: 关闭防火墙 开启Telnet服务:“我的电脑”-->“管理”-->“服务”-->Telnet开启 2.电 ...

  9. 标准IO缓冲机制

    参考资料: https://q16964777.iteye.com/blog/2228244 知道缓冲有几种模式:无缓冲.行缓冲.全缓冲.通过判断FILTE中的 _flags 的判断可以知道究竟是那种 ...

  10. divinglaravel.com

    https://divinglaravel.com/ 这是一个深入 laravel 的学习网站