对棋盘横纵坐标的解读

str1="f3"

str2="e9"

x=abs(str1[0]-str2[0])

y=abs(str1[1]-str1[1])

如果x==y,在一条斜线上

如果x==0或者y==0,在同一横行,或者同一列

注意:我们谈的是x个和y个单位,所以加绝对值

解题思路:找规律:

王:x和y中较大的那个值

后:两个位置如果在一条横线,一条竖线,一条斜线,输出1

否则,输出2,对于后,任意两个不在一条横线,一条竖线,一条斜线的的位置,两步必到

车:如果在同一竖,同一行,一步就到,无论在不在一条斜线上都两步必到

象:x+y能被2整除就能到达,否则输出Inf

在能到达的情况下,又分为走一步和走两步

走一步:x==y

走两步:直接else

#include <stdio.h>
#include <stdlib.h>
#include<math.h> int main()
{
int cases;
char str1[],str2[];
scanf("%d",&cases);
while(cases--)
{
int x,y;
scanf("%s %s",str1,str2);
x=abs(str1[]-str2[]);
y=abs(str1[]-str2[]);
if(x==&&y==){
printf("0 0 0 0\n");
continue;
}
//王
if(x>=y)//x=y,也就是两个位置在一条斜线上,无论输出x还是y都一样
printf("%d ",x);
else
printf("%d ",y);
//后
if(x==||y==||x==y)
printf("%d ",);
else
printf("%d ",);
//车
if(x==||y==)
printf("%d ",);
else
printf("%d ",);
//象
if((x+y)%==)
{
if(x==y)
printf("%d\n",);
else
printf("%d\n",);
}
else
printf("Inf\n");
}
return ;
}
 

poj1657---chessboard的更多相关文章

  1. POJ1657 Distance on chessboard

    Distance on Chessboard Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25623   Accepted ...

  2. poj-1657 Distance on Chessboard

    c语言解决 代码:#include <stdio.h>#include <stdlib.h> int main(){    int num,i;    scanf(" ...

  3. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  4. CodeForces445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. FJOI省队集训 chessboard

    (题目懒得打字了,建议到新窗口查看) 显然这玩意儿是可以按位搞的...然后就是一个裸的最小割模型? 然而这样做理论上只有30分实际上有40分. 事实上我们可以发现,每一列的取值只和上一列有关,这样我们 ...

  6. [poj2446]Chessboard

    Description 给定一个m×n的棋盘,上面有k个洞,求是否能在不重复覆盖且不覆盖到洞的情况下,用2×1的卡片完全覆盖棋盘. Input 第一行有三个整数n,m,k(0<m,n<=3 ...

  7. UESTC 1851 Kings on a Chessboard

    状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...

  8. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

  9. poj 2446 Chessboard (二分匹配)

    Chessboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12800   Accepted: 4000 Descr ...

  10. 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏

    DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. jQuery学习-事件之绑定事件(三)

    在上一篇<jQuery学习-事件之绑定事件(二)>我们了解了jQuery的dispatch方法,今天我们来学习下handlers 方法: handlers: function( event ...

  2. 让乌龟在提交cocos2d-x版本时自动去掉不需要的东东

    引擎版本:2.1.4 ide:vs2012 一般协作开发情况下,有意思无意将bin.obj等一些目录添加到版本管理中是很烦人的事儿,在VS中不断地编译程序集和提交将带来版本暴增问题.如果你用的是乌龟S ...

  3. 图片文件,图片文件流和BASE64加密字符串之间的转换,以及图片的BASE64加密字符串再jsp上如何显示

    http://blog.csdn.net/sidongxue2/article/details/43036373

  4. Guava缓存器源码分析——删除消息

    Guava缓存器的删除消息机制 测试代码——             LoadingCache<String, Integer> cache = CacheBuilder.newBuild ...

  5. ios的标志常量

    1 dec 2 fixed 3 hex 4 internal 5 left 6 oct 7 right 8 scientific 9 showbase 10 showpoint 11 showpos ...

  6. 函数(jquery)

    <script type="text/javascript"> function makeArray(arg1, arg2){    return [ this, ar ...

  7. 郁闷的C小加(一)(后缀表达式)

    郁闷的C小加(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说 ...

  8. HDU 2602 Bone Collector - from lanshui_Yang

           题目大意:有n件物品,每件物品均有各自的价值和体积,给你一个容量为 V 的背包,问这个背包最多能装的物品的价值是多少?        解题思路:这是一道0 - 1 背包的简单模板题,也是 ...

  9. UVA - 10098 - Generating Fast (枚举排列)

    思路:生成全排列,用next_permutation.注意生成之前先对那个字符数组排序. AC代码: #include <cstdio> #include <cstring> ...

  10. SQL 数据类型、约束、索引及视图

    一.数据类型:整数:int,bigint,smallint小数:float,real,decimal(长度,精度),numeric(长度,精度)字符:char(n),varchar(n) 8000英文 ...