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 ...
随机推荐
- C#导出EXCEL(DataTable导出EXCEL)
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.I ...
- DG的数据保护模式
DG的数据保护模式 数据保护膜有三种: – Maximum protection – Maximum availability – Maximum performance Maximum protec ...
- 2017国家集训队作业[agc006e]Rotate 3x3
2017国家集训队作业[agc006e]Rotate 3x3 题意: 给你一个\(3*N\)的网格,每次操作选择一个\(3*3\)的网格,旋转\(180^\circ\).问可不可以使每个位置\(( ...
- Vue 国家省市三级联动
在网上查阅一下,基本上是省市区三级联动,国家省市的就只能自己动手了. 样式就根据自己的需要去调整了. JSON数组太长,就折叠放在了后面. 效果图: <!DOCTYPE html> < ...
- 洛谷——P2678 跳石头
https://www.luogu.org/problem/show?pid=2678#sub 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着 ...
- .Net 开源控件 NPlot使用小结
NPlot是一款非常难得的.Net平台下的图表控件,能做各种曲线图,柱状图,饼图,散点图,股票图等,而且它免费又开源,使用起来也非常符合程序员的习惯.授权方式为BSD许可证. 下载链接: http:/ ...
- python实现获取文件列表中每一个文件keyword
功能描写叙述: 获取某个路径下的全部文件,提取出每一个文件里出现频率最高的前300个字.保存在数据库其中. 前提.你须要配置好nltk #!/usr/bin/python #coding=utf-8 ...
- 使用wget工具抓取网页和图片 及 相关工具几个
想保存一些网页,最后找到这 wget 的 shell脚本,虽然不是太理想,亲测可用呢. 使用wget工具抓取网页和图片 来源 https://my.oschina.net/freestyletim ...
- Android学习笔记进阶18之画图并保存图片到本地
1.首先创建一个Bitmap图片,并指定大小: 2.在该图片上创建一个新的画布Canvas,然后在画布上绘制,并保存即可: 3.需要保存的目录File,注意如果写的目录如“/sdcard/so ...
- Spring CORS
转载:Spring MVC 4.2 增加 CORS 支持 http://spring.io/blog/2015/06/08/cors-support-in-spring-framework http: ...