http://poj.org/problem?id=2014

嘻嘻2014要到啦,于是去做Prob.ID 为2014的题~~~~祝大家新年快乐~~

题目大意:

给你一个最大宽度的矩形,要求把小矩形排放在内,只有当这一行小矩形的宽度超过最大宽度后,才能放入下一行。

求最后放好后的宽度和高度。

(具体看题目吧,好像表述得不太清楚)

思路:

就按题目给定矩形的顺序直接来模拟就好了。。

不用旋转不用排序各种不要。。。

#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=2000;
struct window
{
int width;
int height;
}a[MAXN]; int main()
{
int maxwidth;
while(~scanf("%d",&maxwidth),maxwidth)
{
int len=0;
while(scanf("%d%d",&a[len].width,&a[len].height))
{
if(a[len].width==-1 && a[len].height ==-1)
break;
len++;
} int ans_height=0;
int maxheight=0;
int curwidth=0;
int ans_width=0;
for(int i=0;i<len;i++)
{
if(curwidth + a[i].width >maxwidth)//放到下一行
{
ans_width=max(ans_width,curwidth);//更新最大的宽度
ans_height+=maxheight; //更新高度
curwidth=a[i].width; //当前的宽度就是这块的宽
maxheight=a[i].height; //当前这一行最大高就是这块的高
}
else//放到这一行
{
curwidth+=a[i].width; //更新总宽度
maxheight=max(a[i].height,maxheight); //更新最大的高度
ans_width=max(ans_width,curwidth); //更新宽度
}
}
printf("%d x %d\n",ans_width,ans_height+maxheight);
}
return 0;
}

POJ 2014 Flow Layout 模拟的更多相关文章

  1. POJ 2014:Flow Layout 模拟水题

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

  2. POJ2014 Flow Layout

      Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3161   Accepted: 2199 Description A f ...

  3. Flow Layout

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

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

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

  5. HDU 2494/POJ 3930 Elevator(模拟)(2008 Asia Regional Beijing)

    Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartmen ...

  6. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

  7. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  8. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  9. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

随机推荐

  1. Oracle 练习

    --简单的select语句select deptno,dname,loc from DEPT where deptno='40';--描述表结构 部门表desc dept;--雇员表desc emp; ...

  2. Mac使用Docker-machine訪问docker publish port

    Step 1.Export the port in your container(docker-machine or boot2docker) 首先,要保证你公布port的image已经run起来了. ...

  3. [PWA] Deal with caches in PWA

    The takeway is to know when we should cache the content? When we should clean the caches? 1. When sh ...

  4. Android线程池(二)——ThreadPoolExecutor及其拒绝策略RejectedExecutionHandler使用演示样例

    MainActivity例如以下: package cc.vv; import java.util.concurrent.LinkedBlockingQueue; import java.util.c ...

  5. 程序猿的量化交易之路(14)--Cointrader数据表(2)

    Cointrader表结构 转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrader.top 设置(se ...

  6. oralce的系统用户system的输入口令怎么找回?遇见ORA-28000: the account is locked怎么解锁?

    好几个月前安装的Oracle软件忽然想用就忘记了当初设置的口令了,今天查了下怎么找回. 以一个用户jqz/jqz(曾经建立的一个用户.幸亏还记得)的身份登录后: SQL> connect/as ...

  7. 2.2 Consumer API官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 2.2 Consumer API 2.2.消费者API 随着0..0版本,我们已经增 ...

  8. Windows 下 Sublime Text 默认打开方式问题解决办法

    Sublime Text 2 是很受ACMer喜爱的文本编辑器 但是绿色版删除后无法设置为默认打开方式...而且网上也没有给出明确的解决办法 注册表的解决办法: 删除 HKEY_CURRENT_USE ...

  9. RocketMQ集群消费的那些事

    说明 RocketMQ集群消费的时候,我们经常看到类似注释里面 (1,(2 的写法,已经有时候有同学没注意抛异常的情况就是(3 模拟的情况.那么这3种情况到底是怎么样的呢?你是否都了然于心呢?下面我们 ...

  10. 4.auto详解

    #include <iostream> using namespace std; template <calss T1,class T2> auto add(T1 t1, T2 ...