标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3161 | Accepted: 2199 |
Description
Input
Output
Sample Input
35
10 5
20 12
8 13
-1 -1
25
10 5
20 13
3 12
-1 -1
15
5 17
5 17
5 17
7 9
7 20
2 10
-1 -1
0
Sample Output
30 x 25
23 x 18
15 x 47
Source
纯模拟。
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #define LL long long 7 using namespace std; 8 const int mxn=500010; 9 int read(){ 10 int x=0,f=1;char ch=getchar(); 11 while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 12 while(ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 13 return x*f; 14 } 15 int limit=0; 16 int now=0; 17 int w=0; 18 int h=0; 19 int last=0; 20 int main(){ 21 int x,y; 22 while(1){ 23 limit=read(); 24 if(!limit)break; 25 w=h=last=now=0; 26 while(1){ 27 x=read();y=read(); 28 if(x==-1 && y==-1){ 29 printf("%d x %d\n",w,h); 30 break; 31 } 32 if(now+x<=limit){ 33 now+=x; 34 w=max(w,now); 35 h=max(h,last+y); 36 } 37 else{ 38 now=x; 39 w=max(now,w); 40 last=h; 41 h=last+y; 42 } 43 // printf("now: %d %d\n",w,h); 44 } 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5944331.html