比赛 |
NOIP2008集训模拟4 |
评测结果 |
AWWWWWWWWW |
题目名称 |
彩色穿孔卡片 |
最终得分 |
10 |
用户昵称 |
zhai |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-13 09:43:23 |
显示代码纯文本
program punch;
const
max=10000;
type
sz=array[1..2,1..max]of longint;
sx=array[0..max]of boolean;
var
c:sz;
f1,f2:text;
n:integer;
i,j1,j2,h,t:integer;
ans:integer;
a,b:longint;
flag:sx;
procedure zhao(var h:integer;x:longint;var j:integer);
var
k:integer;
begin
while (h<>t)do begin
k:=(h+t)div 2;
if x>c[1,k] then h:=k+1
else t:=k;
end;
j:=h;
if x>c[1,h] then inc(j);
end;
procedure pai(q:integer);
var
i:integer;
begin
if a<>c[1,j1] then begin
for i:=t downto j1 do begin
c[1,i+1]:=c[1,i];
c[2,i+1]:=c[2,i];
end;
inc(t);
c[1,j1]:=a;
end;
if b<>c[1,j2] then begin
for i:=t downto j2 do begin
c[1,i+1]:=c[1,i];
c[2,i+1]:=c[2,i];
end;
inc(t);
c[1,j2]:=b;
end;
for i:=j1 to j2 do c[2,i]:=q;
end;
begin
assign(f1,'punch.in');reset(f1);
assign(f2,'punch.out');rewrite(f2);
fillchar(c,sizeof(c),0);
fillchar(flag,sizeof(flag),false);
j1:=0;t:=2;
j2:=0;
readln(f1,n);
readln(f1,c[1,1],c[1,2]);
c[1,2]:=1;c[2,2]:=1;
for i:=2 to n do begin
readln(f1,a,b);
h:=1;
zhao(h,a,j1);
zhao(h,b,j2);
pai(i);
end;
ans:=0;
for i:=1 to t do flag[c[2,i]]:=true;
for i:=1 to n do if flag[i] then inc(ans);
write(f2,ans);
close(f1);
close(f2);
end.