对棋盘横纵坐标的解读

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. js数组的操作<转>

    转自 http://blog.csdn.net/xcxinghai/article/details/13502583 PS(个人理解): 1) 数组项的数据类型可以是混合多样的,同时可以含string ...

  2. php 数据结构 hash表

    hash表 定义 hash表定义了一种将字符组成的字符串转换为固定长度(一般是更短长度)的数值或索引值的方法,称为散列法,也叫哈希法.由于通过更短的哈希值比用原始值进行数据库搜索更快,这种方法一般用来 ...

  3. linux命令——scp

    scp linux系统之间基于ssh登录的安全copy文件或者目录.本地[local]—— 远程[remote]{文件} scp local_file remote_username@remote_i ...

  4. android 为TextView添加边框

    今天需要在TextView上面添加一个边框,但是TextView本身不支持边框,所以只能采用其他方式,在网上查询了一下,主要有三种方式可以实现1.带有边框的透明图片2.使用xml的shape设置3继承 ...

  5. 在esx上 docker的网络桥接

    docker:/root# docker run -itd --net=none --name zjtest8_haproxy 192.168.32.150:5000/zjzc_centos6.5_m ...

  6. L1 正则 和 L2 正则的区别

    L1,L2正则都可以看成是 条件限制,即 $\Vert w \Vert \leq c$ $\Vert w \Vert^2 \leq c$ 当w为2维向量时,可以看到,它们限定的取值范围如下图: 所以它 ...

  7. Android UI ActionBar功能-启动ActionBar

    官方帮助文档:http://wear.techbrood.com/training/basics/actionbar/index.html ------------------------------ ...

  8. poj 2686 Traveling by Stagecoach ---状态压缩DP

    题意:给出一个简单带权无向图和起止点,以及若干张马车车票,每张车票可以雇到相应数量的马. 点 u, v 间有边时,从 u 到 v 或从 v 到 u 必须用且仅用一张车票,花费的时间为 w(u, v) ...

  9. C语言中一些非常酷的技巧(cool tricks)

    来自Quora,认为不错,就实践了一下. 1.  #if 0 ...... #endif 块中的内容不会被编译,由于凝视不同意嵌套,我们能够把临时不用的代码块放在 这里面. 2. 数组初始化的时候能够 ...

  10. cocos2d-x for wp8 设置横竖屏

    在主project文件(xxx.cpp , xxx为你的项目名)中, 函数名为void xxx::SetWindow(CoreWindow^ window) 相关代码片例如以下: <pre na ...