Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 3161   Accepted: 2199

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

  1. 35
  2. 10 5
  3. 20 12
  4. 8 13
  5. -1 -1
  6. 25
  7. 10 5
  8. 20 13
  9. 3 12
  10. -1 -1
  11. 15
  12. 5 17
  13. 5 17
  14. 5 17
  15. 7 9
  16. 7 20
  17. 2 10
  18. -1 -1
  19. 0

Sample Output

  1. 30 x 25
  2. 23 x 18
  3. 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=;
  9. int read(){
  10. int x=,f=;char ch=getchar();
  11. while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
  12. while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
  13. return x*f;
  14. }
  15. int limit=;
  16. int now=;
  17. int w=;
  18. int h=;
  19. int last=;
  20. int main(){
  21. int x,y;
  22. while(){
  23. limit=read();
  24. if(!limit)break;
  25. w=h=last=now=;
  26. while(){
  27. x=read();y=read();
  28. if(x==- && y==-){
  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 ;
  47. }

POJ2014 Flow Layout的更多相关文章

  1. Flow Layout

    --------------siwuxie095                             将根面板 contentPane 的布局切换为 Flow Layout     Flow La ...

  2. Collection View Programming Guide for iOS---(四)---Using the Flow Layout

      Using the Flow Layout使用流布局 The UICollectionViewFlowLayout class is a concrete layout object that y ...

  3. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  4. Collection View 自定义布局(custom flow layout)

    Collection view自定义布局 一般我们自定义布局都会新建一个类,继承自UICollectionViewFlowLayout,然后重写几个方法: prepareLayout():当准备开始布 ...

  5. POJ 2014 Flow Layout 模拟

    http://poj.org/problem?id=2014 嘻嘻2014要到啦,于是去做Prob.ID 为2014的题~~~~祝大家新年快乐~~ 题目大意: 给你一个最大宽度的矩形,要求把小矩形排放 ...

  6. Flutter 布局(九)- Flow、Table、Wrap详解

    本文主要介绍Flutter布局中的Flow.Table.Wrap控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. 1. Flow A widget that implements the ...

  7. Border Layout

    ------------------siwuxie095                             根面板 contentPane 的默认布局就是 Border Layout     B ...

  8. 细说Java主流日志工具库

    概述 在项目开发中,为了跟踪代码的运行情况,常常要使用日志来记录信息. 在Java世界,有很多的日志工具库来实现日志功能,避免了我们重复造轮子. 我们先来逐一了解一下主流日志工具. java.util ...

  9. iOS6新特征:UICollectionView介绍

    http://blog.csdn.net/eqera/article/details/8134986 1.1. Collection View 全家福: UICollectionView, UITab ...

随机推荐

  1. 8 Explicit Animations 指明的动画 笔记

    8 Explicit Animations 指明的动画 笔记     If you want something done right, do it yourself. 如果你想让事情做好,那就自动来 ...

  2. iOS开发-Runtime详解

    iOS开发-Runtime详解 简介 Runtime 又叫运行时,是一套底层的 C 语言 API,其为 iOS 内部的核心之一,我们平时编写的 OC 代码,底层都是基于它来实现的.比如: [recei ...

  3. Redis杂谈

    这是2015年初应邀在南华智闻作技术交流时所作的Redis方面的一个presentation. 因为原件是Keynote格式,已经转成PDF,点击下面链接打开或者下载PDF: Redis 杂谈

  4. sql server 2000备份还原数据库

    转载请注明出处:http://blog.csdn.net/neochan1108/article/details/79248017 备份: -- Create the backup device fo ...

  5. Database coalesce

    coalesce 语法 注意:连接操作符“||”是一个值得注意的例外. 例如,空值加任何值都是空值,空值 乘任何值也都是空值,依此类推. 参数 expression 任何类型的表达式. n 表示可以指 ...

  6. Using URL Schemes to Communicate with Apps

    要素:1)通信双方:2)协议:3)支持机制(系统,进行协议注册):4)数据 https://developer.apple.com/library/content/documentation/iPho ...

  7. 如何开发、本地测试、发布 Laravel 扩展包?

    如何开发.本地测试.发布 Laravel 扩展包?  Laravel/ 1年前/  4022 /  11   现在已经有了很多,关于如何开发 Laravel 扩展包的文章.但是大多文章写的太过片面,不 ...

  8. python 字符与字节 json序列和反序列及支持的类型

    b = b"demo" s = "demo" # 字符串转字节 s = bytes(s, encoding = "utf8") s = st ...

  9. uva1660 Cable TV Network

    点连通度:最少删除几个点使图不连通 拆点就变成了最小割 注意编号.画图就知道u’连v,v’连u. 技巧:不需要枚举S,T.固定S,枚举T即可 这种输入很烦, scanf(" (%d,%d)& ...

  10. softmax_regression完成mnist手写体数据集的识别

    ---恢复内容开始--- import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnis ...