Pagini recente » Cod sursa (job #823159) | Cod sursa (job #374597) | Cod sursa (job #119124) | Cod sursa (job #113139) | Cod sursa (job #81979)
Cod sursa(job #81979)
#include<stdio.h>
#include<math.h>
long int t, a, b, x, y, xx, yy, dx, dy, contor;
int main()
{
freopen("taxi.in","r",stdin);
freopen("taxi.out","w",stdout);
scanf("%ld",&t);
while (t--)
{
scanf("%ld %ld %ld %ld %ld %ld",&a,&b,&x,&y,&xx,&yy);
dx=x-xx; if (dx<0) dx*=(-1);
dy=y-yy; if (dy<0) dy*=(-1);
if (dx==0 && dy==0) printf("%ld\n",a*b);
else
if (dx>dy) printf("%ld\n",b+1);
else
if (dx<dy) printf("%ld\n",a+1);
else
if (dx==dy)
{
contor+=dx-1;
if (x<xx && y>yy) contor+=(((1+x)*(y+1))+(a-xx+1)*(b-yy+1));
else
if (x<xx && y<yy) contor+=((1+y)*(a-xx+1)+(1+x)*(b-yy+1));
else
if (x>xx && y>yy) contor+=((1+yy)*(a-x+1)+(1+xx)*(b-y+1));
else
if (x>xx && y<yy) contor+=(((1+xx)*(y+1))+(a-x+1)*(b-yy+1));
printf ("%ld\n",contor);
}
}
return 0;
}