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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章