POJ 2014 Flow Layout 模拟
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 模拟的更多相关文章
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- POJ2014 Flow Layout
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3161 Accepted: 2199 Description A f ...
- Flow Layout
--------------siwuxie095 将根面板 contentPane 的布局切换为 Flow Layout Flow La ...
- Collection View Programming Guide for iOS---(四)---Using the Flow Layout
Using the Flow Layout使用流布局 The UICollectionViewFlowLayout class is a concrete layout object that y ...
- 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 ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
随机推荐
- JCameraView 仿微信拍照Android控件(点击拍照,长按录小视频)
JCameraView 控件介绍 这是一个模仿微信拍照的Android开源控件,主要的功能有如下: 点击拍照. 前后摄像头的切换. 长按录视频(视频长度为10秒内). 长按录视频的时候,手指上滑可以放 ...
- 关于html(meta的常用的用法)
http://www.haorooms.com/post/html_meta_ds
- 03010_防止SQL注入
1.预处理对象 (1)使用PreparedStatement预处理对象时,建议每条sql语句所有的实际参数,都使用逗号分隔: String sql = "insert into sort(s ...
- Duboo入门示例(Idea开发环境)
在学习Dubbo分布式框架时的官方入门例子,很有代表性.简单清晰. 有关Dubbo的概念.概述和简单的配置文件,可以看官方文档的简述 会很快对Duboo有个整体的概念. 准备工作: 下载示例,点击这里 ...
- PatentTips - Improving security in a virtual machine host
BACKGROUND Computer viruses are a common problem for computer users. One typical mode of attack is t ...
- sql%rowcount 返回影响行数
oracle中.返回影响行数是:If sql%rowcount 举例: update ut_calenderStatus t set t.calenderstatus=pi_flg, t.m=pi_M ...
- WINDOWS 安装 M2Crypto for Python2.7
WINDOWS 安装 M2Crypto for Python2.7运行环境 WIN8.1 + Python2.7 + VS2008(Microsoft Visual C++ 9.0) VS2008 可 ...
- 14.NPM 常用命令
转自:http://www.runoob.com/nodejs/nodejs-npm.html PM提供了很多命令,例如install和publish,使用npm help可查看所有命令. NPM提供 ...
- React 和 Vue 对比
React 和 Vue 有许多相似之处,它们都有: * 使用 Virtual DOM * 提供了响应式 (Reactive) 和组件化 (Composable) 的视图组件. * 将注意力集中保持 ...
- 洛谷 P2640 神秘磁石
P2640 神秘磁石 题目背景 在遥远的阿拉德大陆,有一种神秘的磁石,是由魔皇制作出来的, 题目描述 1.若给他一个一维坐标系,那么他的磁力一定要在素数坐标的位置上才能发挥的最大(不管位置坐标的大小, ...