B. Wallpaper

#99
B. Wallpaper
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (different rooms can have different dimensions, including height).

Boris chose m types of wallpaper to paper the walls of the rooms with (but it is not necessary to use all the types). Each type of wallpaper is sold in rolls of a fixed length and width (the length, naturally, shows how long the unfolded roll will be). In addition, for each type we know the price of one roll of this type.

The wallpaper of each type contains strips running along the length of the roll. When gluing the strips must be located strictly vertically (so the roll cannot be rotated, even if the length is less than the width). Besides, a roll can be cut in an arbitrary manner, but the joints of glued pieces should also be vertical. In addition, each room should be papered by only one type of wallpaper. And pieces of the same roll cannot be used to paper different rooms. That is, for each room the rolls are purchased separately. Also, some rolls can be used not completely.

After buying an apartment Boris is short of cash, so he wants to spend the minimum money on wallpaper. Help him.

<p< p="" style="font-family: verdana, arial, sans-serif; font-size: 14px; line-height: 21px; "><p< p="">
Input
<p< p="">

The first line contains a positive integer n (1 ≤ n ≤ 500) — the number of rooms in Boris's apartment.

Each of the next n lines contains three space-separated positive integers — the length, width and height of the walls in a given room in meters, respectively.

The next line contains a positive integer m (1 ≤ m ≤ 500) — the number of available wallpaper types.

Each of the following m lines contains three space-separated positive integers — the length and width in meters of a given wallpaper and the price of one roll, respectively.

All numbers in the input data do not exceed 500. It is guaranteed that each room can be papered using these types of wallpaper.

<p< p=""><p< p="">
Output
<p< p="">

Print a single number — the minimum total cost of the rolls.

<p< p=""><p< p="">
Sample test(s)
<p< p=""><p< p="">
input
1
5 5 3
3
10 1 100
15 2 320
3 19 500
output
640
<p< p=""><p< p="">
Note
<p< p="">

Note to the sample:

The total length of the walls (the perimeter) of the room is 20 m.

One roll of the first type can be cut into pieces to get three vertical 1 meter wide strips, ergo you need 7 rolls of this type, the price equals 700.

A roll of the second type can be cut into pieces to get five 2 meter wide strips, we need 2 rolls, the price is 640.

One roll of the third type can immediately paper 19 meters out of 20, but we cannot use other types and we have to buy a second roll, the price is 1000.

写这个博客的时候心情感觉好好。希望我们能越来越好mt。

题意:Boris 想把各个房间的墙壁贴上壁纸,首先给你一个数n表示房间的个数,接着n行每行有3个数分别是每个房间的长,宽和高。接着是输入一个m表示有m种壁纸可以选择。再接下来的m行,每行有3个数分别表示壁纸的长,宽和价格。要求把各个房间都贴好的最少费用。

贴壁纸的时候几个要求

1,壁纸的长要严格对应墙壁的高,壁纸的宽严格对应墙壁的宽。

2,壁纸是可以剪成符合要求的规格,比如第一种类型的壁纸,长是10,宽是1;所以根据需要可以剪成3块长是3宽是1的,还有一个1x1的就可以扔掉。

3每个房间用剩的不能给其他的房间用。

解题方法:其实四个墙壁展开就是一个矩形,这样的话矩形的长 len=2*(rooms[i][0]+rooms[i][1]);rooms[i][0],rooms[i][1]分别是第i个房间的长和宽。矩形的宽width = rooms[i][2](rooms[i][2]是房间 i 的高);因为每个房间所需的费用是需要的壁纸的roll的数量乘以对应壁纸的价格。怎样求所需壁纸的roll的数量呢?首先算出每roll壁纸可以裁减成几小块符合要求的壁纸(即长等于墙壁的高,宽等于原来壁纸的宽的壁纸)pic = types][j][0]/rooms[i][2],然后算出需要多少roll壁纸sum=len/(types[j][1]*pic);需要注意的是当len不能整除types[j][1]*pic的时候(即还有墙壁没有贴住),说明还需要多加1roll的壁纸。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>


using namespace std;


int main()
{
int room,type;
int rooms[500+5][4];
int types[500+5][4];
int i,j;
int best,ans;
int len,width;
int mod,pic,sum;
while(scanf("%d",&room)!=EOF)
{
for(i = 0;i<room;i++)
{
scanf("%d%d%d",&rooms[i][0],&rooms[i][1],&rooms[i][2]);
}
scanf("%d",&type);
for(i = 0;i<type;i++)
{
scanf("%d%d%d",&types[i][0],&types[i][1],&types[i][2]);
}
best = 0x7fffffff;
ans = 0;
for(i = 0;i<room;i++)
{
len = 2*rooms[i][1]+2*rooms[i][0];
width = rooms[i][2];
best = 0x7ffffff;
for(j = 0;j<type;j++)
{
if(types[j][0]>=width)
{
pic = types[j][0]/rooms[i][2];         //1roll可以分成多少pic
mod = (len%(pic*types[j][1]))>0?1:0;   //需不需要多加1roll
sum = len/(pic*types[j][1]);           //需要多少roll
sum += mod;                            //需不需要多加1roll
sum = sum*types[j][2];                 //需要多少费用
if(best>sum)
{
best = sum;
}
}
}
ans += best;
}
printf("%d\n",ans);
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值