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 ...
随机推荐
- python image show()方法的预览问题
在windows下面使用PIL中Image的show()函数时,执行下列代码: from PIL import Image img = Image.open("1.png") ...
- C# 堆栈的数据结构 (二)
堆栈是一种常用的数据结构,并且是线性表操作的子集,即操作受限的线性表.因此需要用到Clist 线性表类 public class CStack { private Clist m_List;//创建链 ...
- css案例学习之继承关系
代码 <html> <head> <title>继承关系</title> <style> body{ color:blue; /* 颜色 * ...
- aix knowlgdgecenter
http://www-01.ibm.com/support/knowledgecenter/ssw_aix_53/com.ibm.aix.install/doc/insgdrf/HT_insgdrf_ ...
- nginx启动关闭
[root@localhost sbin]# ./nginx -s reload [root@localhost sbin]# ./nginx -s stop [root@localhost sbin ...
- UICollectionView基础学习
相信了解UICollectionView的也一定听过瀑布流吧,开始之前先提供两个瀑布流,有时间的可以深入研究研究 https://github.com/dingpuyu/WaterFall https ...
- Cube(规律)
Cube Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- POJ2553-The Bottom of a Graph
id=2553">主题链接 题意:求解Bottom(G).即集合内的点能够互相到达. 思路:有向图的强连通.缩点,找出出度为0的点,注意符合的点要按升序输出. 代码: #include ...
- BZOJ 2186 SDOI2008 沙拉公主的困惑 数论
题目大意:给定询问组数T和取模数P,每次询问给定两个整数n和m,求1~(n!)的数中与m!互质的数个个数模P (m<=n) 首先T<=1W,暴力肯定过不去,我们须要预处理一些东西 首先我们 ...
- easyui的样式easyui-textbox的一个bug
easyui-testbox这个样式很恶心,用了这个就不能用传统的JQ来取值了,最近在使用上又发现了一个问题,就是赋值为0时,在输入框上会不显示,坑. <input class="ea ...