| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
象的情况可以用直线解析方法求解(还有要注意是”Inf“ 不是"inf")#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin>>n;
int count=0;
while(++count<=n)
{
char a[2],b[2];
scanf("%s %s",a,b);
int x1=a[0]-'a'+1,x2=b[0]-'a'+1;
int y1=a[1]-'0',y2=b[1]-'0';
int king=0,queen=0,horse=0,car=0;
if ((x1==x2)&&(y1==y2))
{
printf("0 0 0 0\n");
continue;
}
king=abs(x1-x2)<abs(y1-y2)? abs(y1-y2):abs(x1-x2); //王
if(x1==x2||y1==y2||abs(x1-x2)==abs(y1-y2)) queen =1;
else queen =2; //后
if(x1==x2||y1==y2) horse=1;
else horse=2;// 马
if(abs(x1-x2)==abs(y1-y2)) car=1;
else if((x1+x2+y2-y1)%2==0&&(y1+y2+x2-x1)%2==0) car=2; // 车
if(car==0) printf("%d %d %d %s\n",king,queen,horse,"Inf");
else printf("%d %d %d %d\n",king,queen,horse,car);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator