USACO 1.2.1 Milking Cows

来源:互联网 发布:ps美工教程好学吗 编辑:程序博客网 时间:2024/05/18 00:56
.comment { color: #999999; font-style: italic; }.pre { color: #000099; }.string { color: #009900; }.char { color: #009900; }.float { color: #996600; }.int { color: #999900; }.bool { color: #000000; font-weight: bold; }.type { color: #FF6633; }.flow { color: #FF0000; }.keyword { color: #990000; }.operator { color: #663300; font-weight: bold; }
/* 
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.

 
.comment { color: #999999; font-style: italic; }.pre { color: #000099; }.string { color: #009900; }.char { color: #009900; }.float { color: #996600; }.int { color: #999900; }.bool { color: #000000; font-weight: bold; }.type { color: #FF6633; }.flow { color: #FF0000; }.keyword { color: #990000; }.operator { color: #663300; font-weight: bold; }
/* 
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.
原创粉丝点击