POJ 1657

题意:难得一道中文题目。。。不解释了(⊙o⊙)…

传送门:http://poj.org/problem?id=1657

思路: 定义string s,g;
s代表起始位置,g代表目标位置;
王:取abs(g[0]-s[0])与abs(g[1]-s[1])中较大的;
王后:当情况满足g[0]==s[0]||g[1]==s[1]||abs(g[0]-s[0])==abs(g[1]-s[1])时,取1, 否则取2;
车:当情况满足g[0]==s[0]||g[1]==s[1]时,取1,否则取2;
象(最蛋疼的):当满足abs(g[0]-s[0])==abs(g[1]-s[1])时取1,
满足g[0]==s[0]&&(abs(g[1]-s[1]==2)||abs(g[1]-s[1]==4)||abs(g[1]-s[1]==6))或
g[1]==s[1]&&(abs(g[0]-s[0]==2)||abs(g[0]-s[0]==4)||abs(g[0]-s[0]==6))时,取2,

象取2时,要求 g[0]==s[0]( g[1]==s[1]),并且从s[1]到g[1]( s[0]到g[0] )的格子数为奇数,包括s[1],g[1](s[0],g[0])在内。

其他情况取Inf。

代码:
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
inline int max(int &a,int &b)
{
   return a>b?a:b;
}
int main()
{
   string s,g;
   int n,k,q,c,e;
   cin>>n;
   while(n--)
   {
       cin>>s>>g;
       if(s==g){cout<<0<<" "<<0<<" "<<0<<" "<<0<<endl;continue;}
       k=max(abs(g[0]-s[0]),abs(g[1]-s[1]));
       if(g[0]==s[0]||g[1]==s[1]||abs(g[0]-s[0])==abs(g[1]-s[1]))q=1;
       else q=2;
       if(g[0]==s[0]||g[1]==s[1])c=1;
       else c=2;
       if(abs(g[0]-s[0])==abs(g[1]-s[1]))e=1;
       else if(g[0]==s[0]&&(abs(g[1]-s[1]==2)||abs(g[1]-s[1]==4)||abs(g[1]-s[1]==6)))e=2;
       else if(g[1]==s[1]&&(abs(g[0]-s[0]==2)||abs(g[0]-s[0]==4)||abs(g[0]-s[0]==6)))e=2;
       else e=0;
       if(e==0)cout<<k<<" "<<q<<" "<<c<<" "<<"Inf"<<endl;
       else cout<<k<<" "<<q<<" "<<c<<" "<<e<<endl;
   }
   return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值