题意:难得一道中文题目。。。不解释了(⊙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;
}
#include<string>
#include<cmath>
using
inline
{
}
int
{
}