NOIP2016第三题

题目:https://www.luogu.org/problem/show?pid=2058

刘可盈同学的分析及代码:

var
  n,i,j:integer;
  l,ans:longint;
  t:array [0..100000] of longint;//时间
  x:array[0..100000,0..300] of integer;//国籍
  s:array[0..100000] of boolean;//s用于统计有几种国籍
begin
  assign(input,'port.in');reset(input);
  assign(output,'port.out');rewrite(output);
  readln(n);
  for i:=1 to n do begin
    read(t[i],x[i,0]);//读入到达时间和到达的人数,第i组到达人数存放在x的第i行第0格
    for j:=1 to x[i,0] do read(x[i,j]);//读入国籍
    fillchar(s,sizeof(s),false);
    ans:=0;
    for j:=i downto 1 do begin        //从i向前统计国籍
      if t[i]-t[j]>=86400 then break; //当时间差大于86400时退出循环,因为时间是递加的,所以前面一定没有符合条件的了
      for l:=1 to x[j,0] do s[x[j,l]]:=true;//把这组数中的所有的国籍赋为真
    end;
    for l:=1 to 100000 do if s[l] then ans:=ans+1;//统计有多少国籍为真
    writeln(ans);
  end;
  close(input);close(output);
end.
posted @ 2017-01-12 15:16  lsnoip  阅读(109)  评论(0)    收藏  举报