Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

该死的题

Posted by Mato_beat_wish at 2009-08-06 22:19:20 on Problem 1009
什么数据都试过了,还是WA,

是不是题目看错了,或是格式问题?

附代码:(Pascal)

CONST
    p1: ARRAY[1..8] OF LONGINT = (-1, -1, -1, 0, 0, 1, 1, 1);
    p2: ARRAY[1..8] OF LONGINT = (-1, 0, 1, -1, 1, -1, 0, 1);
VAR
   n, m, z1, st0, sr0: LONGINT;
   x1, y1, x2, y2, num: ARRAY[1..1000] OF LONGINT;
   rn, rkk: ARRAY[1..1000000] OF LONGINT;
PROCEDURE f01(kk: LONGINT; VAR x0, y0: LONGINT);
BEGIN
    x0 := kk DIV m + 1; y0 := kk MOD m;
    IF y0 = 0 THEN BEGIN y0 := m; DEC(x0); END;
END;
PROCEDURE f02(x0, y0: LONGINT; VAR kk: LONGINT);
BEGIN
    kk := (x0 - 1) * m + y0;
END;
PROCEDURE init;
VAR
   i, k0: LONGINT;
BEGIN
    READLN(m);
    IF m = 0 THEN BEGIN WRITELN(0); HALT; END;
    k0 := 1; st0 := 0;
    WHILE TRUE DO BEGIN
          INC(st0);
          READLN(num[st0], i);
          IF (num[st0] = 0) AND (i = 0) THEN BEGIN DEC(st0); BREAK; END;
          f01(k0, x1[st0], y1[st0]);
          f01(k0 + i - 1, x2[st0], y2[st0]);
          k0 := k0 + i;
    END;
    DEC(k0);
    n := k0 DIV m; sr0 := 0; z1 := k0 MOD m;
    IF z1 = 0 THEN z1 := m ELSE INC(n);
END;
PROCEDURE add(nm0, k0: LONGINT);
BEGIN
    IF sr0 = 0 THEN BEGIN
       INC(sr0);
       rn[sr0] := nm0; rkk[sr0] := k0;
       EXIT;
    END;
    IF nm0 = rn[sr0] THEN INC(rkk[sr0], k0) ELSE BEGIN
       INC(sr0);
       rn[sr0] := nm0; rkk[sr0] := k0;
    END;
END;
FUNCTION se1(x0, y0, ii: LONGINT): LONGINT;
VAR
   i, kk0, kk1, kk2: LONGINT;
BEGIN
    f02(x0, y0, kk0);
    FOR i:=ii DOWNTO 1 DO BEGIN
        f02(x1[i], y1[i], kk1);
        f02(x2[i], y2[i], kk2);
        IF (kk0 >= kk1) AND (kk0 <= kk2) THEN EXIT(i);
    END;
END;
FUNCTION se2(x0, y0, ii: LONGINT): LONGINT;
VAR
   i, kk0, kk1, kk2: LONGINT;
BEGIN
    f02(x0, y0, kk0);
    FOR i:=ii TO st0 DO BEGIN
        f02(x1[i], y1[i], kk1);
        f02(x2[i], y2[i], kk2);
        IF (kk0 >= kk1) AND (kk0 <= kk2) THEN EXIT(i);
    END;
END;
PROCEDURE xx1(x0, y0, nm0, ii: LONGINT);
VAR
   i: LONGINT;
   x00, y00, t, max: LONGINT;
BEGIN
    max := 0;
    FOR i:=1 TO 8 DO BEGIN
        x00 := x0 + p1[i]; y00 := y0 + p2[i];
        IF (x00 < 1) OR (x00 > n) THEN CONTINUE;
        IF (y00 < 1) OR (y00 > m) THEN CONTINUE;
        IF (x00 = n) AND (y00 > z1) THEN CONTINUE;
        IF i <= 4 THEN t := se1(x00, y00, ii) ELSE t := se2(x00, y00, ii);
        IF ABS(num[t] - nm0) > max THEN max := ABS(num[t] - nm0);
    END;
    add(max, 1);
END;
PROCEDURE xx2(i, j1, j2, nm0, ii: LONGINT);
VAR
   sq1, sq2, k0, k1, k2, a1, a2: LONGINT;
BEGIN
    IF (i = 1) AND (i = n) THEN BEGIN
       xx1(i, j1, nm0, ii);
       IF j2 - j1 > 1 THEN add(0, j2 - j1 - 1);
       IF j2 > j1 THEN xx1(i, j2, nm0, ii);
       EXIT;
    END;
    IF i = 1 THEN BEGIN
       sq2 := se2(i + 1, j1, ii);
       k0 := j1;
       REPEAT
            IF x2[sq2] > i + 1 THEN BEGIN
               xx1(i, k0, nm0, ii);
               IF j2 - k0 > 1 THEN add(ABS(nm0 - num[sq2]), j2 - k0 - 1);
               IF j2 > k0 THEN xx1(i, j2, nm0, ii);
               EXIT;
            END ELSE BEGIN
               IF y2[sq2] >= j2 THEN BEGIN
                  xx1(i, k0, nm0, ii);
                  IF j2 - k0 > 1 THEN add(ABS(nm0 - num[sq2]), j2 - k0 - 1);
                  IF j2 > k0 THEN xx1(i, j2, nm0, ii);
                  EXIT;
               END;
               xx1(i, k0, nm0, ii);
               IF y2[sq2] - k0 > 1 THEN add(ABS(nm0 - num[sq2]), y2[sq2] - k0 - 1);
               IF y2[sq2] > k0 THEN xx1(i, y2[sq2], nm0, ii);
               INC(sq2);
               k0 := y1[sq2];
            END;
       UNTIL FALSE;
       EXIT;
    END;
    IF (i = n) OR ((i = n - 1) AND (j1 > z1)) THEN BEGIN
       sq1 := se1(i - 1, j1, ii);
       k0 := j1;
       REPEAT
            IF x2[sq1] > i - 1 THEN BEGIN
               xx1(i, k0, nm0, ii);
               IF j2 - k0 > 1 THEN add(ABS(nm0 - num[sq1]), j2 - k0 - 1);
               IF j2 > k0 THEN xx1(i, j2, nm0, ii);
               EXIT;
            END ELSE BEGIN
               IF y2[sq1] >= j2 THEN BEGIN
                  xx1(i, k0, nm0, ii);
                  IF j2 - k0 > 1 THEN add(ABS(nm0 - num[sq1]), j2 - k0 - 1);
                  IF j2 > k0 THEN xx1(i, j2, nm0, ii);
                  EXIT;
               END;
               xx1(i, k0, nm0, ii);
               IF y2[sq1] - k0 > 1 THEN add(ABS(nm0 - num[sq1]), y2[sq1] - k0 - 1);
               IF y2[sq1] > k0 THEN xx1(i, y2[sq1], nm0, ii);
               INC(sq1);
               k0 := y1[sq1];
            END;
       UNTIL FALSE;
       EXIT;
    END;
    sq1 := se1(i - 1, j1, ii); sq2 := se2(i + 1, j1, ii); k0 := j1;
    REPEAT
         k1 := y2[sq1]; k2 := y2[sq2];
         IF x2[sq1] > i - 1 THEN k1 := j2;
         IF x2[sq2] > i + 1 THEN k2 := j2;
         IF k1 >= k2 THEN BEGIN
            xx1(i, k0, nm0, ii);
            IF k2 - k0 > 1 THEN BEGIN
               a1 := ABS(nm0 - num[sq1]);
               a2 := ABS(nm0 - num[sq2]);
               IF a1 > a2 THEN add(a1, k2 - k0 - 1) ELSE add(a2, k2 - k0 - 1);
            END;
            IF k2 > k0 THEN xx1(i, k2, nm0, ii);
            IF k2 = j2 THEN EXIT;
            INC(sq2);
            IF k1 = k2 THEN INC(sq1);
            k0 := k2 + 1;
         END ELSE BEGIN
            xx1(i, k0, nm0, ii);
            IF k1 - k0 > 1 THEN BEGIN
               a1 := ABS(nm0 - num[sq1]);
               a2 := ABS(nm0 - num[sq2]);
               IF a1 > a2 THEN add(a1, k1 - k0 - 1) ELSE add(a2, k1 - k0 - 1);
            END;
            IF k1 > k0 THEN xx1(i, k1, nm0, ii);
            IF k1 = j2 THEN EXIT;
            INC(sq1);
            k0 := k1 + 1;
         END;
    UNTIL FALSE;
END;
PROCEDURE xx3(i, j1, j2, nm0, ii: LONGINT);
BEGIN
    IF (i = n - 1) AND (j1 <= z1) AND (j2 > z1) THEN BEGIN
       xx2(i, j1, z1, nm0, ii);
       xx2(i, z1 + 1, j2, nm0, ii);
    END ELSE xx2(i, j1, j2, nm0, ii);
END;
PROCEDURE xxx;
VAR
   i: LONGINT;
BEGIN
    FOR i:=1 TO st0 DO BEGIN
        IF x1[i] = x2[i] THEN BEGIN
           xx3(x1[i], y1[i], y2[i], num[i], i);
           CONTINUE;
        END;
        IF x1[i] + 1 = x2[i] THEN BEGIN
           xx3(x1[i], y1[i], m, num[i], i);
           xx3(x2[i], 1, y2[i], num[i], i);
           CONTINUE;
        END;
        IF x1[i] + 2 = x2[i] THEN BEGIN
           xx3(x1[i], y1[i], m, num[i], i);
           xx3(x1[i] + 1, 1, m, num[i], i);
           xx3(x2[i], 1, y2[i], num[i], i);
           CONTINUE;
        END;
        IF x1[i] + 3 = x2[i] THEN BEGIN
           xx3(x1[i], y1[i], m, num[i], i);
           xx3(x1[i] + 1, 1, m, num[i], i);
           xx3(x1[i] + 2, 1, m, num[i], i);
           xx3(x2[i], 1, y2[i], num[i], i);
           CONTINUE;
        END;
        xx3(x1[i], y1[i], m, num[i], i);
        xx3(x1[i] + 1, 1, m, num[i], i);
        add(0, (x2[i] - x1[i] - 3) * m);
        xx3(x2[i] - 1, 1, m, num[i], i);
        xx3(x2[i], 1, y2[i], num[i], i);
    END;
END;
PROCEDURE pri;
VAR
   i: LONGINT;
BEGIN
    WRITELN(m);
    FOR i:=1 TO sr0 DO WRITELN(rn[i], ' ', rkk[i]);
    WRITELN(0, ' ', 0);
END;
BEGIN
    REPEAT
         init;
         xxx;
         pri;
    UNTIL FALSE;
END.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator