Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
注意!!!!!!!!!!最后的是小写的x 附带自己的垃圾代码,对你理解题意应该有所帮助,不要想的太复杂 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include <stdio.h> //Each rectangle is between 1 and 80 units wide (inclusive) and between 1 and 100 units high (inclusive). int main(void) { int m = 0;// 1 <= m <= 80 maximum width of the resulting window int i = 0, count = 0; int dimensions[16][2] ={0}; int max_x = 0, max_y_0 = 0, max_y_1 = 0; int cur_x = 0; while(1) { max_x =0, max_y_0 = 0, max_y_1 = 0, cur_x = 0, count = 0; i = 0; scanf("%d", &m); if(m == 0) break; while(1) { scanf("%d%d", &dimensions[i][0], &dimensions[i][1]); if((dimensions[i][0] == -1) && (dimensions[i][1] == -1)) break; else { i++; count++; } } for(i = 0; i < count; i++) { if((cur_x + dimensions[i][0]) > m) { cur_x = 0; cur_x += dimensions[i][0]; if(cur_x >max_x) max_x = cur_x; max_y_0 += max_y_1; if(i == count-1) max_y_0 += dimensions[i][1]; max_y_1 = dimensions[i][1]; } else { cur_x += dimensions[i][0]; if(cur_x > max_x) max_x = cur_x; if(dimensions[i][1] > max_y_1) max_y_1 = dimensions[i][1]; if(i == count-1) max_y_0 += max_y_1; } } printf("%d x %d\n", max_x, max_y_0); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator