| ||||||||||
| 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 | |||||||||
短小精悍贴个代码,都可以推导的大量?运算可能可读性不好x,y分别代表x,y轴差值
王是x,y中最大值,后是x!=y?1:2,特别注意x==0&&y==0的时候是0,车是x==0||y==0?1:2也是在x&&y==0时是0
最后象稍复杂,观察图不难发现当x,y同奇偶(这时起点终点同色)的时候可到达,不然就是Inf
于是可到达情况下容易得出x==y?1:2
除了王以外其他人跑遍图不超过2步(除了到不了)
#include <stdio.h>
int main()
{
int N;
char a,c;
int b,d,x,y;
scanf("%d",&N);
getchar();
while(N--)
{
scanf("%c%d %c%d",&a,&b,&c,&d);
getchar();
x=a-c>0?a-c:c-a;
y=b-d>0?b-d:d-b;
printf("%d %d %d ",x>y?x:y,x==0&&y==0?0:(x==0||y==0?1:(x!=y?2:1)),x==0&&y==0?0:((x==0||y==0)?1:2));
if((x&1)==(y&1))
{
printf("%d\n",x==0&&y==0?0:(x==y?1:2));
}
else
{
puts("Inf");
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator