POJ 2014:Flow Layout 模拟水题
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3091 | Accepted: 2148 |
Description
continues from left to right again. Given a set of rectangular dimensions and a maximum window width, you are to write a program that computes the dimensions of the final window after all the rectangles have been placed in it.
For example, given a window that can be at most 35 units wide, and three rectangles with dimensions 10 x 5, 20 x 12, and 8 x 13, the flow layout manager would create a window that looked like the figures below after each rectangle was added.

The final dimensions of the resulting window are 30 x 25, since the width of the first row is 10+20 = 30 and the combined height of the first and second rows is 12+13 = 25.
Input
and at most 15 lines, each containing the dimensions of one rectangle, width first, then height. The end of the list of rectangles is signaled by the pair -1 -1, which is not counted as the dimensions of an actual rectangle. Each rectangle is between 1 and
80 units wide (inclusive) and between 1 and 100 units high (inclusive).
Output
Sample Input
35
10 5
20 12
8 13
-1 -1
25
10 5
20 13
3 12
-1 -1
15
5 17
5 17
5 17
7 9
7 20
2 10
-1 -1
0
Sample Output
30 x 25
23 x 18
15 x 47
给了一个固定长度的空间,要往里面摆箱子,不够相应的空间箱子就要放到下一“行”,问最终的长度和宽度。宽度不一定是给定的宽度,可能有没有用掉的情况。
模拟水题。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int zong_weight,num;
int weight[20],height[20]; int main()
{
int i,sum,length,zong_length,max_weight;
while(scanf("%d",&zong_weight)==1)
{
if(zong_weight==0)
break; num=1;
sum=0;
length=0;
zong_length=0;
max_weight=0; while(scanf("%d%d",&weight[num],&height[num])==2)
{
if(weight[num]+height[num]==-2)
break;
num++;
} for(i=1;i<=num;i++)
{
if(sum+weight[i]<=zong_weight)
{
sum += weight[i];
length=max(length,height[i]);
max_weight=max(max_weight,sum);
}
else
{
sum=weight[i];
zong_length += length;
length=height[i];
}
}
zong_length += length;
cout<<max_weight<<" x "<<zong_length<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 2014:Flow Layout 模拟水题的更多相关文章
- POJ 2014 Flow Layout 模拟
http://poj.org/problem?id=2014 嘻嘻2014要到啦,于是去做Prob.ID 为2014的题~~~~祝大家新年快乐~~ 题目大意: 给你一个最大宽度的矩形,要求把小矩形排放 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- poj 1658 Eva's Problem(水题)
一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...
- hdu 5003 模拟水题 (2014鞍山网赛G题)
你的一系列得分 先降序排列 再按0.95^(i-1)*ai 这个公式计算你的每一个得分 最后求和 Sample Input12530 478Sample Output984.1000000000 # ...
随机推荐
- docker 运行ubuntu镜像 apt-get update 问题
docker运行ubuntu镜像后,apt-getupdate出现问题如下: 根据上面的报错大概是因为....文件上没有生效(生效还需要10d 13h 33min 45s),看来是时间不够啊,需要等待 ...
- 洛谷 P4391 [BOI2009]Radio Transmission 无线传输
题目传送门 解题思路: 本题所要求的循环节,其实就是最长公共前缀的前缀长度减去前后缀重叠的一部分 AC代码: #include<iostream> #include<cstdio&g ...
- 剑指offer,双指针法,vector输出不完美
原因:由于在第一个res push_back给allRes的时候allRes的列已经确定,所以在输出的时候会输出一些多余的东西,在输出的时候不好处理 #include <iostream> ...
- java关键字“static”
Java中static使用方法 1.static静态变量 静态变量:每个类只有一个,所有实例共享: 实例变量:每个实例只有一个: package test2; import java.lang.Str ...
- 【剑指Offer】面试题28. 对称的二叉树
题目 请实现一个函数,用来判断一棵二叉树是不是对称的.如果一棵二叉树和它的镜像一样,那么它是对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 ...
- web.xml的配置过程中也需要注意顺序问题
配置WEB.XML的配置文件过程中发现: 直接红叉,鼠标放在红叉出信息如下: cvc-complex-type.2.4.a: Invalid content was found starting wi ...
- 洛谷 P2549 计算器写作文
题目传送门 解题思路: 背包,f[i]表示计算器位数为i时,可获得的最大分值. 本题与01背包不同的地方在于,物品的摆放顺序对答案是有影响的,例如两个字符串a,b,那么就会出现a+b和b+a两种情况( ...
- tf.argmax()函数作用
tf.argmax()函数原型: def argmax(input, axis=None, name=None, dimension=None, output_type=dtypes.int64) 作 ...
- 九十五、SAP中查看自定义包的所有模块,对象,函数主,事务等
一.输入SE80 二.选择包,再查下Z* 三.可以看到,查下出来的包 四.可以看到我们想要的内容了
- docker 安装好后启动异常解决
一个月前在虚拟机中根据视频教程安装了docker 启动docker后执行 systemctl status docker 出现了异常,具体如下: [root@joinApp2 ~]# systemct ...