Editorial for Repair City Hall


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

var m,n,i,j:byte;
    a:array[1..200,1..200] of char;
    b:array[1..200] of integer;

procedure count(j:byte);
var i,t:byte;
begin
     t:=0; i:=1;
     while i<=n do
     begin
          if a[i,j]='0' then
          begin
               t:=i;
               repeat
                     inc(i);
               until (a[i,j]='1') or (i>n);
               inc(b[i-t]);
          end;
          inc(i);
     end;
end;

begin
     readln(m,n);
     for i:=1 to m do
     begin
          for j:=1 to n do
              read(a[i,j]);
          readln;
     end;
     fillchar(b,sizeof(b),0);
     for j:=1 to n do
         count(j);
     for i:=1 to m do
         if b[i]>0 then writeln(i,' ',b[i]);
end.

Code mẫu của happyboy99x

#include<cstdio>

#define N 200
char s[N+1][N+1];
int c[N+1], m, n;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d%d",&m,&n);
    for(int i = 0; i < m; ++i) scanf("%s", s[i]);
    for(int j = 0; j < n; ++j) {
        for(int i = 0; i < m; ) {
            if(s[i][j] == 0x31) ++i;
            else {
                int st = i;
                for(; i < m && s[i][j] == 0x30; ++i);
                ++c[i - st];
            }
        }
    }
    for(int i = 1; i <= m; ++i)
        if(c[i]) printf("%d %d\n", i, c[i]);
    return 0;
}

Code mẫu của ladpro98

program mcityhall;
uses    math;
const   fi='';
        maxN=222;
var     a:array[0..maxN,0..maxN] of longint;
        res:array[1..maxN] of longint;
        m,n:longint;

procedure input;
var     f:text;
        i,j:longint;
        c:char;
begin
        assign(f,fi);
        reset(f);
        readln(f,m,n);
        for i:=1 to m do
        begin
                for j:=1 to n do
                begin
                        read(f,c);
                        if c='1' then a[i,j]:=1
                        else
                        a[i,j]:=0;
                end;
                readln(f);

        end;
        close(f);
end;

procedure init;
var     i:longint;
begin
        for i:=1 to n do
        a[m+1,i]:=1;
end;

procedure process;
var     i,j,k:longint;
begin
        for j:=1 to n do
        begin
                i:=1;
                while i<=m do
                begin
                        while (i<=m) and (a[i,j]=1) do inc(i);
                        if i>m then break;
                        k:=i+1;
                        while a[k,j]=0 do inc(k);
                        inc(res[k-i]);
                        i:=k;
                end;
        end;
end;

procedure output;
var     I:LONGINT;
begin
        for i:=1 to m do
        begin
                if res[i]>0 then
                writeln(i,' ',res[i]);
        end;
end;

begin
        input;
        init;
        process;
        output;
end.

Code mẫu của RR

{$R+,Q+}
{$Mode objFPC}
uses math;
const
  FINP='';
  FOUT='';
  MAXN=222;
var
  m,n:longint;
  a:array[-1..MAXN,-1..MAXN] of char;
  d:array[-1..MAXN,-1..MAXN] of longint;
  count:array[1..MAXN] of longint;
  f1,f2:text;
procedure openF;
begin
  assign(f1,FINP); reset(f1);
  assign(f2,FOUT); rewrite(f2);
end;
procedure closeF;
begin
  close(f1);
  close(f2);
end;
procedure inp;
var
  i,j:longint;
begin
  readln(f1,m,n);
  for i:=1 to m do
    begin
      for j:=1 to n do read(f1,a[i,j]);
      readln(f1);
    end;
  for j:=1 to n do
    a[m+1,j]:='1';
end;
procedure solve;
var
  i,j:longint;
begin
  for i:=1 to m do
  for j:=1 to n do
    if a[i,j]='0' then d[i,j]:=d[i-1,j]+1;
  for i:=1 to m do
  for j:=1 to n do
    if (a[i,j]='0') and (a[i+1,j]='1') then inc(count[d[i,j]]);
end;
procedure ans;
var
  i:longint;
begin
  for i:=1 to m do
    if count[i]>0 then
      writeln(f2,i,' ',count[i]);
end;
begin
  openF;
  inp;
  solve;
  ans;
  closeF;
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
main()
{
long m,n,a[202],u,v;
char s[202][202];
scanf("%ld %ld",&m,&n);
for(long i=1;i<=m;i++)
  {
  scanf("%s",s[i]);
  a[i]=0;
  } 
for(long i=0;i<n;i++)
  {
  u=1;v=1;
  while(u!=m+1&&u!=m+2)
    {
    if(s[u][i]=='1')
      u++;
    else
      {
      v=u+1;
      while(v!=m+1)
        {
        if(s[v][i]=='0')
          v++;
        else
          break;
        }
      //printf("%ld %ld %ld\n",u,v,i);  
      a[v-u]++;
      u=v+1;
      }
    }
  }  
for(long i=1;i<=m;i++)
  if(a[i]!=0)
    printf("%ld %ld\n",i,a[i]); 
//getch();
}

Code mẫu của ll931110

{$MODE DELPHI}
Program MCITYHAL;
        Const
                input  = '';
                output = '';
                   max = 200;
        Var
                  c: array[1..max,1..max] of boolean;
                  a: array[1..max] of integer;
                n,m: integer;

Procedure init;
          Var
                  f: text;
                i,j: integer;
                 ch: char;
          Begin
                Assign(f, input);
                        Reset(f);

                Readln(f, m, n);
                For i:= 1 to m do
                  Begin
                     For j:= 1 to n do
                        Begin
                                Read(f, ch);
                                If ch = '1' then c[i,j]:= true else c[i,j]:= false;
                        End;
                     Readln(f);
                  End;

                Close(f);
          End;

Procedure solve;
          Var
                current,i,j: integer;
          Begin
                Fillchar(a, sizeof(a), 0);

                current:= 0;
                For j:= 1 to n do
                  Begin
                           For i:= 1 to m do if not c[i,j] then inc(current)
                                        else if current <> 0 then
                                                Begin
                                                        inc(a[current]);
                                                        current:= 0;
                                                End;
                        If current <> 0 then
                                Begin
                                        inc(a[current]);
                                        current:= 0;
                                End;
                  End;
          End;

Procedure printresult;
          Var
                f: text;
                i: integer;
          Begin
                Assign(f, output);
                        Rewrite(f);

                For i:= 1 to max do
                        if a[i] <> 0 then writeln(f, i, ' ', a[i]);

                Close(f);
          End;

Begin
        init;
        solve;
        printresult;
End.

Code mẫu của khuc_tuan

// {$APPTYPE CONSOLE}
 {$mode delphi}

var
    i, j, cur, len, m, n : integer;
    a : array[0..222,0..222] of char;
    count : array[0..222] of integer;

begin
    readln(m,n);
    for i:=0 to m-1 do
        readln(a[i]);
    for j:=0 to n-1 do
    begin
        cur := -1;
        for i:=0 to m-1 do
        begin
            if (a[i,j]='0') and ((i=0) or (a[i-1,j]='1')) then cur := i;
            if (a[i,j]='1') and (cur<>-1) then
            begin
                len := i - cur;
                inc(count[len]);
                cur := -1;
            end;
        end;
        if cur<>-1 then inc(count[m-cur]);
    end;
    for i:=1 to m do if count[i] > 0 then writeln(i, #32, count[i]);
end.

Comments

Please read the guidelines before commenting.


There are no comments at the moment.