Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

象的情况可以用直线解析方法求解(还有要注意是”Inf“ 不是"inf")

Posted by z1160y at 2009-05-30 02:39:08 on Problem 1657
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator