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

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

should the answer be 0

i think that code also answer 0