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. windows下go语言环境

    1  liteIDE ,随便装哪儿都行 2  GO语言包 安装  ,我安装到了 c:\go  (顺便给个地址下载地址  https://golang.org/dl/  ) 3  GCC编译器 安装,同 ...

  2. 最大子段和 模板题 51Nod 1049

    N个整数组成的序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续子段和的最大值.当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,- ...

  3. jQuery对象与js对象转换

    前言 jq方法和js的方法属性是不能互相使用的,所以有时候就需要转一下,下面就介绍下方法. js对象转化为jQuery对象 var box=document.getElementById(" ...

  4. tomcat日志配置之一自带log

    问题 tomcat每次启动时,自动在logs目录下生产以下日志文件,且每天都会生成对应日期的一个文件,造成日志文件众多: localhost.2012-07-05.txt catalina.2012- ...

  5. CODEVS——T1183 泥泞的道路

    时间限制: 1 s  空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解  查看运行结果 题目描述 Description CS有n个小区,并且任意小区之间都有两条单向道路(a到 ...

  6. 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

    P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...

  7. wpf app全局变量传参方法(代码片段 )

    清空某行绑定的行数据: int RowIndex = datagrid.SelectedIndex; _Table.Rows[RowIndex]["AVERAGE_PRICE"] ...

  8. jodd-servlet工具集锦

    Jodd提供了许多servlet和jsp相关的工具. Utils ServletUtils类集成了不同的servlet工具,你可以检测multipart请求,读取授权头,下载预备,cookie操作,读 ...

  9. JAVA MessageDigest(MD5加密等)

    转自http://blog.csdn.net/hudashi/article/details/8394158 一.概述 java.security.MessageDigest类用于为应用程序提供信息摘 ...

  10. 18/9/9牛客网提高组Day1

    牛客网提高组Day1 T1 中位数 这好像是主席树??听说过,不会啊... 最后只打了个暴力,可能是n2logn? 只过了前30%  qwq #include<algorithm> #in ...