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

为什么我考虑了出发地和目的地一样的情况还是WA...泪!!

Posted by cpp00648027 at 2007-03-04 17:53:26 on Problem 1657
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int max,count=0,mini,big,i;
	int p[4];
	int hori,upri;//hori是横坐标之差,upri是纵坐标之差
	char star[2],dest[2];//star是出发地,dest是目的地
	cin>>max;
	while(count < max) {
		if( max>20 || max<0 )
			break;
		cin>>star>>dest;
		if( star[0]>'f' || star[0]<'a' || star[1]>'8' || star[1]<'1')
			break;
		hori = abs(star[0] - dest[0]);
		upri = abs(star[1] - dest[1]);
		if(hori > upri) {
			mini = upri;
			big = hori;
		}
		else {
			mini = hori;
			big = upri;
		}

		if( hori==0 && upri==0 )//原地不动
			for(i=0;i<4;i++)
				p[i]=0;

		else if(mini == 0 && big != 0) {//连线的斜率为0或不存在
			p[0] = big;
			p[1] = 1;
			p[2] = 1;
			p[3] = -1;//无法到达的标记为-1
		}

		else if(hori == upri && hori != 0 ) {//连线的斜率为±1
			p[0] = mini;
			p[1] = 1;
			p[2] = 2;
			p[3] = 1;
		}

		else {//其他情况
			p[0] = big;
			p[1] = 2;
			p[2] = 2;
			p[3] = -1;
		}

		for(i=0;i<3;i++) {
			if(p[i]!=-1)
				cout<<p[i]<<" ";
			else
				cout<<"Inf ";
		}
		if(p[3]!=-1)
			cout<<p[3];
		else
			cout<<"Inf";

		cout<<endl;
		count++;
	}
	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