POJ 2014:Flow Layout 模拟水题
2015-08-11 10:20
399 查看
Flow Layout
Description
A flow layout manager takes rectangular objects and places them in a rectangular window from left to right. If there isn't enough room in one row for an object, it is placed completely below all the objects in the first row at the left edge, where the order
continues from left to right again. Given a set of rectangular dimensions and a maximum window width, you are to write a program that computes the dimensions of the final window after all the rectangles have been placed in it.
For example, given a window that can be at most 35 units wide, and three rectangles with dimensions 10 x 5, 20 x 12, and 8 x 13, the flow layout manager would create a window that looked like the figures below after each rectangle was added.
The final dimensions of the resulting window are 30 x 25, since the width of the first row is 10+20 = 30 and the combined height of the first and second rows is 12+13 = 25.
Input
The input consists of one or more sets of data, followed by a final line containing only the value 0. Each data set starts with a line containing an integer, m, 1 <= m <= 80, which is the maximum width of the resulting window. This is followed by at least one
and at most 15 lines, each containing the dimensions of one rectangle, width first, then height. The end of the list of rectangles is signaled by the pair -1 -1, which is not counted as the dimensions of an actual rectangle. Each rectangle is between 1 and
80 units wide (inclusive) and between 1 and 100 units high (inclusive).
Output
For each input set print the width of the resulting window, followed by a space, then the lowercase letter "x", followed by a space, then the height of the resulting window.
Sample Input
Sample Output
给了一个固定长度的空间,要往里面摆箱子,不够相应的空间箱子就要放到下一“行”,问最终的长度和宽度。宽度不一定是给定的宽度,可能有没有用掉的情况。
模拟水题。
代码:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3091 | Accepted: 2148 |
A flow layout manager takes rectangular objects and places them in a rectangular window from left to right. If there isn't enough room in one row for an object, it is placed completely below all the objects in the first row at the left edge, where the order
continues from left to right again. Given a set of rectangular dimensions and a maximum window width, you are to write a program that computes the dimensions of the final window after all the rectangles have been placed in it.
For example, given a window that can be at most 35 units wide, and three rectangles with dimensions 10 x 5, 20 x 12, and 8 x 13, the flow layout manager would create a window that looked like the figures below after each rectangle was added.
The final dimensions of the resulting window are 30 x 25, since the width of the first row is 10+20 = 30 and the combined height of the first and second rows is 12+13 = 25.
Input
The input consists of one or more sets of data, followed by a final line containing only the value 0. Each data set starts with a line containing an integer, m, 1 <= m <= 80, which is the maximum width of the resulting window. This is followed by at least one
and at most 15 lines, each containing the dimensions of one rectangle, width first, then height. The end of the list of rectangles is signaled by the pair -1 -1, which is not counted as the dimensions of an actual rectangle. Each rectangle is between 1 and
80 units wide (inclusive) and between 1 and 100 units high (inclusive).
Output
For each input set print the width of the resulting window, followed by a space, then the lowercase letter "x", followed by a space, then the height of the resulting window.
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
给了一个固定长度的空间,要往里面摆箱子,不够相应的空间箱子就要放到下一“行”,问最终的长度和宽度。宽度不一定是给定的宽度,可能有没有用掉的情况。
模拟水题。
代码:
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #pragma warning(disable:4996) using namespace std; int zong_weight,num; int weight[20],height[20]; int main() { int i,sum,length,zong_length,max_weight; while(scanf("%d",&zong_weight)==1) { if(zong_weight==0) break; num=1; sum=0; length=0; zong_length=0; max_weight=0; while(scanf("%d%d",&weight[num],&height[num])==2) { if(weight[num]+height[num]==-2) break; num++; } for(i=1;i<=num;i++) { if(sum+weight[i]<=zong_weight) { sum += weight[i]; length=max(length,height[i]); max_weight=max(max_weight,sum); } else { sum=weight[i]; zong_length += length; length=height[i]; } } zong_length += length; cout<<max_weight<<" x "<<zong_length<<endl; } return 0; }
相关文章推荐
- E. President and Roads (CF Round #Pi (Div. 2)) 优先队列的Dij+Tarjan找桥
- hdu 1281 棋盘游戏
- C++11 并发指南六( <atomic> 类型详解二 std::atomic )
- session与request
- 19-集合框架工具类-16-常用对象API(集合框架-工具类-Collections-其他方法&将非同步集合转成同步集合的方法)
- python正则表达式 re (二)sub
- 杭电 1503 Advanced Fruits(lcs)
- C#怎样从指定服务器上下载指定文件到本地电脑上
- 柯氏分页
- POJ 2014:Flow Layout 模拟水题
- UITextField
- poj3320
- volatile的作用
- 新blog
- Apache Mahout的Taste基于Hadoop实现协同过滤推荐引擎的代码分析
- ckplayer cuplayer的使用
- Android-自定义Dialog
- Codeforces 567D One-Dimensional Battle Ships
- NPOI进行Excel文件的导出
- 设计模式之简单工厂模式