Cod sursa(job #81979)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 5 septembrie 2007 16:00:43
Problema Culori Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#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;
}