比赛 20100925练习 评测结果 AAAAAAAAAAA
题目名称 晚餐队列安排 最终得分 100
用户昵称 1102 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-25 11:31:15
显示代码纯文本
program diningb;
var n,i,w,m:longint;
a:array[1..30000]of longint;
f:array[0..30000,1..2]of longint;

{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}
function min(x,y:longint):longint;
begin
  if x>y then
    min:=y
  else
    min:=x;
end;
{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}


begin
  m:=0;w:=0;
  assign(input,'diningb.in');
  reset(input);
  assign(output,'diningb.out');
  rewrite(output);
  read(n);
  while w<>n do
    begin
      for i:=1 to n do
        begin
          inc(w);
          read(a[i]);
        end;
        f[0,1]:=0; f[0,2]:=0;
      for i:=1 to n do
        if a[i]=1 then
          begin
            f[i,1]:=f[i-1,1];
            f[i,2]:=min(f[i-1,1],f[i-1,2]+1);
          end
        else
          begin
            f[i,1]:=f[i-1,1]+1;
            f[i,2]:=min(f[i-1,1]+1,f[i-1,2]);
          end;
         if f[n,1]>f[n,2] then
    write(f[n,2])
  else
    write(f[n,1]);
    end;
  close(input);
  close(output);
end.