USACO 1.2.1 Milking Cows

/* 
PROG: milk2
LANG: C++
*/

#include <iostream>
 #include <fstream>
 #include <string>
 #include <cmath>
 
using namespace std;
 ifstream fin("milk2.in");
ofstream fout("milk2.out");
int
n;
int
begin=10000001,end=0;
bool
t[1000001];
int
min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int
main()
{

fin>>n;
int
a,b;
memset(t,0,sizeof(t));
 for
(int i=1;i<=n;i++)
{

fin>>a>>b;
for
(int i=a+1;i<=b;i++)
t[i]=true;
begin=min(begin,a);
end=max(b,end);
}

int
x=0,y=0;
int
l1=0,l2=0;
for
(int i=begin+1;i<=end;i++)
if
(t[i])
{

y=0,x++;
l1=max(x,l1);
}

else

{

x=0,y++;
l2=max(y,l2);
}

fout<<l1<<' '<<l2<<endl;
return
0;
}
Compiling...
Compile: OK

Executing...
      Test 
1: TEST OK [0.008 secs]
      Test 2: TEST OK [0.008 secs]
      Test 3: TEST OK [0.008 secs]
      Test 4: TEST OK [0.008 secs]
      Test 5: TEST OK [0.06 secs]
      Test 6: TEST OK [0.008 secs]
      Test 7: TEST OK [0.012 secs]
      Test 8: TEST OK [0.02
 secs]

All tests OK.

YOUR PROGRAM ('milk2') WORKED FIRST TIME! 
That's fantastic -- and a rare thing. 
Please accept these special automated congratulations.

 
/* 
PROG: milk2
 LANG: C++
*/

 #include <iostream>
 #include <fstream>
 #include <string>
#include <cmath>
 
using namespace std;
 ifstream fin("milk2.in");
 ofstream fout("milk2.out");
int
n,k=0;
struct qu { int b,e;}q[5001];
int
min(int a,int b){return a<b?a:b;}
int
max(int a,int b){return a>b?a:b;}
int
com(const void *c,const void *d)
 {
qu *cc=(qu *)c;
qu *dd=(qu *)d;
return
cc->b-dd->b;
}

int
main()
{

fin>>n;
for
(int i=1;i<=n;i++)
fin>>q[i].b>>q[i].e;
q[0].b=-11;
qsort(q,n+1,sizeof(q[1]),com);
 int
x=0,y=0;
 qu now;
for
(int i=1;i<=n;i++)
{

now=q[i];
 for(i++;i<=n;i++)
{

if
( now.e>=q[i].b)
{

now.e=max(now.e,q[i].e);
now.b=min(now.b,q[i].b);
}

else

{

x=max(x,now.e-now.b);
y=max(y,q[i].b-now.e);
i=i+l-1;
break
;
}
}
}

x=max(x,now.e-now.b);
fout<<x<< ' '<<y<<endl;
return
0;
}
 
Compiling...
Compile: OK

Executing...
      Test 
1: TEST OK [0 secs]
      Test 2: TEST OK [0 secs]
      Test 3: TEST OK [0 secs]
      Test 4: TEST OK [0.004 secs]
      Test 5: TEST OK [0.004 secs]
      Test 6: TEST OK [0 secs]
      Test 7: TEST OK [0.008 secs]
      Test 8: TEST OK [0.028
 secs]

All tests OK.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值