poj1657---chessboard

对棋盘横纵坐标的解读
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的更多相关文章
- POJ1657 Distance on chessboard
Distance on Chessboard Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25623 Accepted ...
- poj-1657 Distance on Chessboard
c语言解决 代码:#include <stdio.h>#include <stdlib.h> int main(){ int num,i; scanf(" ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- CodeForces445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- FJOI省队集训 chessboard
(题目懒得打字了,建议到新窗口查看) 显然这玩意儿是可以按位搞的...然后就是一个裸的最小割模型? 然而这样做理论上只有30分实际上有40分. 事实上我们可以发现,每一列的取值只和上一列有关,这样我们 ...
- [poj2446]Chessboard
Description 给定一个m×n的棋盘,上面有k个洞,求是否能在不重复覆盖且不覆盖到洞的情况下,用2×1的卡片完全覆盖棋盘. Input 第一行有三个整数n,m,k(0<m,n<=3 ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
- poj 2446 Chessboard (二分匹配)
Chessboard Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12800 Accepted: 4000 Descr ...
- 周赛-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 ...
随机推荐
- 移动端h5摇一摇事件
// 摇一摇动作 //获取加速度信息 //通过监听上一步获取到的x, y, z 值在一定时间范围内的变化率,进行设备是否有进行晃动的判断. //而为了防止正常移动的误判,需要给该变化率设置一个合适的临 ...
- Python之路第五天,基础(5)-序列化和字符串格式化
序列化 Python中用于序列化的两个模块 json 用于『字符串』和『python基本数据类型』间进行转换 pickle 用于『python特有的类型』和『python基本数据类型』间进行转换 js ...
- SQL Server 查看指定表上的索引
解决方案: sys.indexs; ---------------------------------------------------------------------------------- ...
- Example: Develop Web application on Baidu App Engine using CherryPy
In the past few months, I have developed two simple applications on Baidu App Engine. Compared to Go ...
- 【写一个自己的js库】 1.搭个架子先
最近在看<javascript dom 高级程序设计>,想着跟着里面的代码敲一遍吧,也算是做一下学习笔记吧,所以这不是重新发明轮子,只是个学习的过程. 1.先确定自己的命名空间,并且加入几 ...
- 解决 MySQL manager or server PID file could not be found! 的方法
[root@centos var]# service mysqld stop MySQL manager or server PID file could not be found! [F ...
- linux中ctrl+z、ctrl+d和ctrl+c的区别
ctrl+c和ctrl+z都是中断命令,但是他们的作用却不一样.ctrl+c是强制中断程序的执行,而ctrl+z的是将任务中断,但是此任务并没有结束,他仍然在进程中他只是维持挂起的状态,用户可以使用f ...
- 基于Schema的AOP 配置使用详解
原文地址:http://jinnianshilongnian.iteye.com/blog/1418598 基于Schema的AOP从Spring2.0之后通过"aop"命名空间来 ...
- express4.0之后不会解析req.files,必须加一个插件multer
express 4 + 用multer express4.0之后不会解析req.files,必须加一个插件multer http://www.w3school.com.cn/tags/att_form ...
- n!的近似值 (stirling approximation)与 大O记法(big -O- notation)
參考wiki: 1.n!的近似值 (stirling approximation) (中文) http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E9%9D ...