ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1202. Rectangles Travel

can he touch the borders?
Posted by Alyosha Popovich 19 Mar 2002 16:20
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) ?
No
Posted by Mephistos 19 Mar 2002 17:09
u sure? i can't get ac using the following program:
Posted by Alyosha Popovich 19 Mar 2002 20:34
#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());
}
It fails on the following test
Posted by Mephistos 19 Mar 2002 20:54
1
0 0 2 2
so what's the answer for...
Posted by Apiwat 26 Oct 2006 10:01
for
1
0 0 2 2

should the answer be 0

i think that code also answer 0