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 ...
随机推荐
- private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object>();
private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object&g ...
- Atcoder AGC 019 A,B
A - Ice Tea Store Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement You' ...
- Spark存储体系
作为分布式应用,Spark的数据存储在不同机器上.这就涉及到数据的传输,元数据的管理等内容.而且由于Spark可以利用内存和磁盘作为存储介质,这还涉及到了内存和磁盘的数据管理. Spark存储体系架构 ...
- ajax起步 (二)
Ajax的关键在于XMLHttpRequest对象,如下基本用法: <!DOCTYPE html> <html> <head> <meta charset=& ...
- PHP生成RSS报
<?php$sql="select * from wx_zimi ";$res=$dbs->query($sql);$arr=array();while($o=$dbs ...
- JAVASE学习笔记:第十章 SWing经常使用控件类(二)
7.JComboBox 下拉列表 /* * 初始化下拉列表 */ public void addcomb(){ String[] area = {"山西省&qu ...
- git- 仓库创建、修改、提交、撤销
1.仓库创建 zhangshuli@zhangshuli-MS-:~$ mkdir myGit zhangshuli@zhangshuli-MS-:~$ cd myGit/ zhangshuli@zh ...
- sql跳过非工作日(周末和节假日)
简介:场景1:基于开始日期和工期,推算结束日期. 场景2:基于开始日期和结束日期,计算工期 注:需要自己做界面维护工作日表(s_WorkDay)和节假日表(s_SpecialDay) 涉及到的数据表 ...
- Android提示版本号更新操作流程
Android提示版本号更新操作流程 2014年5月8日: andorid的app应用中都会有版本号更新的操作,今天空暇的时候就花了点心思弄了一下.主要技术方面用到了AsyncTask异步载入.htt ...
- Android 使用Wake Lock
为了延长电池的使用寿命,Android设备会在一段时间后使屏幕变暗,然后关闭屏幕显示,最后停止CPU.WakeLock是一个电源管理系统服务功能,应用程序可以使用它来控制设备的电源状态. WakeLo ...