对棋盘横纵坐标的解读

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. Unicode其实是Latin1的扩展。只有一个低字节的Uncode字符其实就是Latin1字符——附各种字符编码表及转换表

    一.概念 1,ASCII             ASCII(American Standard Code for Information Interchange),中文名称为美国信息交换标准代码.是 ...

  2. poj3030

    #include <stdio.h> #include <stdlib.h> int main() { int n,r,e,a; scanf("%d",&a ...

  3. linux学习(二)-目录的操作命令

    Linux命令大全:http://www.jb51.net/linux/ 目录分绝对路径和相对路径 : 绝对路径,在路径前会加  / 相对路径就是相对于当前的路径,直接 路径名即可. 查看目录: cd ...

  4. Hopcroft-Karp算法模版

    #include <cstdio> #include <cstring> #include <vector> #include <queue> #inc ...

  5. Android读写JSON格式的数据之JsonWriter和JsonReader

    近期的好几个月都没有搞Android编程了,逐渐的都忘却了一些东西.近期打算找一份Android的工作,要继续拾起曾经的东西.公司月初搬家之后就一直没有网络,直到今日公司才有网络接入,各部门才開始办公 ...

  6. POJ2186 Popular Cows 【强连通分量】+【Kosaraju】+【Tarjan】+【Garbow】

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 23445   Accepted: 9605 Des ...

  7. HDOJ 2689

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  8. [Phonegap+Sencha Touch] 移动开发36 Phonegap/Cordova项目的图标和启动画面(splashscreen)配置

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/40780111 Phonegap/Cordova项目中的config.xml文件.里面配 ...

  9. ActionBar隐藏修改图标和标题

    有时候在一些子页面或者内容页面,不需要显示ActionBar的标题栏图标.可用如下方式进行设置. 首先获取到ActionBar对象 ActionBar actionBar=getActionBar() ...

  10. jquery设置文本框值 与获取文本框的值

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...