USACO 3.1.5

http://hi.baidu.com/raulliubo/blog/item/9dbecf62a0fc65d9e6113a2e.html

USER: BO LIU [raulliu2]
TASK: contact
LANG: PASCAL

Compiling...
Compile: OK

Executing...
      Test 1: TEST OK [0 secs]
      Test 2: TEST OK [0.004 secs]
      Test 3: TEST OK [0.004 secs]
      Test 4: TEST OK [0.004 secs]
      Test 5: TEST OK [0.048 secs]
      Test 6: TEST OK [0.048 secs]
      Test 7: TEST OK [0.084 secs]

All tests OK.

YOUR PROGRAM ('contact') WORKED FIRST TIME!  That's fantastic
-- and a rare thing.  Please accept these special automated
congratulations.
简单题,不想说什么了。贴程序。

my ugly code :

{
PROG:contact
ID:parachutes
LANG:PASCAL
}

var
     t1, t2, max, a1, b, n, i, j, k, tmp, tot : longint;
     s : string;
     a : array[1 .. 200000] of shortint;
     freq : array[1 .. 8192] of longint;

function change(k : longint) : string;
var
     i : longint;
begin
     change := '';
     repeat
         if odd(k) then
             change := '1' + change
         else
             change := '0' + change;
         k := k shr 1;
     until k = 1;
end;

begin
     assign(input,'contact.in'); reset(input);
     assign(output,'contact.out'); rewrite(output);
     readln(a1, b, n);
     repeat
         readln(s);
         for i := 1 to length(s) do begin
             inc(tot);
             a[tot] := ord(s[i]) - 48;
         end;
     until eof;
     for i := 1 to tot do begin
         tmp := 1;
         for j := i to i + b - 1 do
             if j <= tot then begin
                 tmp := tmp shl 1 + a[j];
                 if j - i + 1 >= a1 then inc(freq[tmp]);
             end;
     end;
     t1 := 1 shl a1;
     t2 := 1 shl (b + 1);
     k := 0;
     for i := 1 to n do begin
         max := 0;
         for j := t1 to t2 do
             if freq[j] > max then
                 max := freq[j];
         if max <> 0 then begin
             if k <> 0 then
                 writeln;
             writeln(max);
             k := 0;
             for j := t1 to t2 do
                 if freq[j] = max then begin
                     inc(k);
                     if k mod 6 = 0 then begin
                         writeln(' ', change(j));
                         k := 0;
                     end
                     else
                     if k <> 1 then write(' ', change(j))
                     else write(change(j));
                     freq[j] := 0;
                 end;
         end
         else break;
     end;
     if k <> 0 then writeln;
     close(input);
     close(output);
end.

posted @ 2009-01-04 12:20  jesonpeng  阅读(134)  评论(0编辑  收藏  举报