码迷,mamicode.com
首页 > 其他好文 > 详细

【USACO】milking cows

时间:2014-09-11 15:10:02      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   for   div   sp   log   

{
ID: anniel11
PROG: milk2
LANG: PASCAL
}
Program milk2;
Var
    ans1,ans2,i,j,n,sum,head,tail:longint;
    a:array[1..5000,1..2] of longint;
    map:array[1..100000] of integer;
    f:array[0..100000,1..2] of integer;
Begin
    fillchar(map,sizeof(map),0);
    ans1:=0;
    ans2:=0;
    Assign(input, milk2.in); reset(input);
    Assign(output, milk2.out); Rewrite(output);
    Readln(n);
    head:=maxlongint;
    tail:=0;
    fillchar(a,sizeof(a),0);
    for i:=1 to n do
    begin
        readln(a[i,1],a[i,2]);
        if a[i,1]<head then head:=a[i,1];
        if a[i,2]>tail then tail:=a[i,2];
        inc(map[a[i,1]]);
        dec(map[a[i,2]]);
    end;
    for i:=head to tail do
    begin

        sum:=sum+map[i];
        if sum>0 then f[i,1]:=f[i-1,1]+1 else f[i,1]:=0;
        if f[i,1]>ans1 then ans1:=f[i,1];
        if sum<=0 then f[i,2]:=f[i-1,2]+1 else f[i,2]:=0;
        if f[i,2]>ans2 then ans2:=f[i,2];
       // writeln(i, ,f[i,1], ,f[i,2]);
    end;
    writeln(ans1, ,ans2);
    close(input);
    close(output);
End.

 

【USACO】milking cows

标签:style   blog   color   os   ar   for   div   sp   log   

原文地址:http://www.cnblogs.com/OmegaIota/p/3966482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!