Pagini recente » Cod sursa (job #3177965) | Cod sursa (job #1400638) | Cod sursa (job #643146) | Cod sursa (job #43400) | Cod sursa (job #197353)
Cod sursa(job #197353)
#include <stdio.h>
#include <string.h>
int M, N, C;
inline void swap(int &a, int &b)
{
int aux = a;
a = b;
b = aux;
}
void brut(void)
{
FILE *fin = fopen("gropi.in", "r");
FILE *fok = fopen("gropi.out", "w");
int i, j, mat[3][256];
int x1, y1, x2, y2, cnt;
memset(mat, 0, sizeof(mat));
fscanf(fin, "%d %d", &C, &N);
for (; N; --N)
{
fscanf(fin, "%d %d", &i, &j);
mat[i][j] = 1;
}
for (fscanf(fin, "%d", &M), i = 1; i <= M; ++i)
{
fscanf(fin, "%d %d %d %d", &x1, &y1, &x2, &y2);
if (y1 > y2)
swap(x1, x2),
swap(y1, y2);
cnt = 1;
while (y1 < y2)
{
if (mat[x1][y1+1])
++cnt, x1 = 3-x1;
else
++cnt, ++y1;
}
fprintf(fok, "%d\n", cnt + (x1 != x2));
}
fclose(fin);
fclose(fok);
}
int main(void)
{
brut();
return 0;
}