Cod sursa(job #197765)

Utilizator c_e_manuEmanuel Cinca c_e_manu Data 5 iulie 2008 19:03:48
Problema Gropi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<stdio.h>
long a[2][100001];
long i,j,n,m,x,y,xx,yy,l,k,g;
int main()
{       freopen("gropi.in","r",stdin);
	freopen("gropi.out","w",stdout);
	scanf("%ld%ld",&n,&g);
	for(i=1;i<=g;i++)
	{       scanf("%ld%ld",&x,&y);
		a[x-1][y-1]=-1;
	}
	scanf("%ld",&m);
	for(l=1;l<=m;l++)
	{       scanf("%ld%ld%ld%ld",&x,&y,&xx,&yy);x--;y--;xx--;yy--;
		if(y>yy){g=yy;yy=y;y=g;
			g=xx;xx=x;x=g;}
		i=x;j=y;k=1;
                while(j!=yy)
                        if(a[i][j+1]!=-1){j++;k++;}
                        else if(1==i){i=0;k++;}
                             else{i=1;k++;}
                if(i!=xx) printf("%ld\n",k+1);
                else      printf("%ld\n",k);
        }
        return 0;
}