can he touch the borders?
Can he touch the borders?
For the following input:
0 0 10 10
10 9 20 20
is there solution? (can he walk like 10,9 ->10,10->11,10, touching
the borders but not walking over them) ?
u sure? i can't get ac using the following program:
#include <stdio.h>
#include <math.h>
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
int N;
int read_and_solve()
{
int i, L = 0;
int lx1, ly1, lx2, ly2, x1, y1, x2, y2, lo, hi;
int X = 1, Y = 1;
scanf("%d %d %d %d %d", &N, &lx1, &ly1, &lx2, &ly2);
for (i = 1; i < N; i++)
{
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
lo = max(y1, ly1);
hi = min(y2, ly2);
if (hi-lo < 2) return -1;
if (Y <= lo) L += (lo+1)-Y, Y = lo+1;
if (Y >= hi) L += Y-(hi-1), Y = hi-1;
L += x1-X, X = x1;
lx1 = x1, ly1 = y1, lx2 = x2, ly2 = y2;
}
L += x2-1-X+abs(y2-1-Y);
return L;
}
void main()
{
printf("%d\n", read_and_solve());
}