Paper Cutting
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 545 | Accepted: 302 |
Description
ACM managers need business cards to present themselves to their customers and partners. After the cards are printed on a large sheet of paper, they are cut with a special cutting machine. Since the machine operation is very expensive, it is necessary to minimize the number of cuts made. Your task is to find the optimal solution to produce the business cards.
There are several limitations you have to comply with. The cards are always printed in a grid structure of exactly a * b cards. The structure size (number of business cards in a single row and column) is fixed and cannot be changed due to a printing software restrictions. The sheet is always rectangular and its size is fixed. The grid must be perpendicular to the sheet edges, i.e., it can be rotated by 90 degrees only. However, you can exchange the meaning of rows and columns and place the cards into any position on the sheet, they can even touch the paper edges.
For instance, assume the card size is 3 * 4 cm, and the grid size 1 * 2 cards. The four possible orientations of the grid are depicted in the following figure. The minimum paper size needed for each of them is stated.
The cutting machine used to cut the cards is able to make an arbitrary long continuous cut. The cut must run through the whole piece of the paper, it cannot stop in the middle. Only one free piece of paper can be cut at once -- you cannot stack pieces of paper onto each other, nor place them beside each other to save cuts.
There are several limitations you have to comply with. The cards are always printed in a grid structure of exactly a * b cards. The structure size (number of business cards in a single row and column) is fixed and cannot be changed due to a printing software restrictions. The sheet is always rectangular and its size is fixed. The grid must be perpendicular to the sheet edges, i.e., it can be rotated by 90 degrees only. However, you can exchange the meaning of rows and columns and place the cards into any position on the sheet, they can even touch the paper edges.
For instance, assume the card size is 3 * 4 cm, and the grid size 1 * 2 cards. The four possible orientations of the grid are depicted in the following figure. The minimum paper size needed for each of them is stated.
![](https://i-blog.csdnimg.cn/blog_migrate/7c33b74187a70e42336cada7e19264ac.jpeg)
The cutting machine used to cut the cards is able to make an arbitrary long continuous cut. The cut must run through the whole piece of the paper, it cannot stop in the middle. Only one free piece of paper can be cut at once -- you cannot stack pieces of paper onto each other, nor place them beside each other to save cuts.
Input
The input consists of several test cases. Each of them is specified by six positive integer numbers, A,B,C,D,E,F, on one line separated by a space. The numbers are:
A and B are the size of a rectangular grid, 1 <= A,B <= 1 000,
C and D are the dimensions of a card in cms, 1 <= C,D <= 1 000, and
E and F are the dimensions of a paper sheet in cms, 1 <= E,F <= 1 000 000.
The input is terminated by a line containing six zeros.
A and B are the size of a rectangular grid, 1 <= A,B <= 1 000,
C and D are the dimensions of a card in cms, 1 <= C,D <= 1 000, and
E and F are the dimensions of a paper sheet in cms, 1 <= E,F <= 1 000 000.
The input is terminated by a line containing six zeros.
Output
For each of the test cases, output a single line. The line should contain the text: "The minimum number of cuts is X.", where X is the minimal number of cuts required. If it is not possible to fit the card grid onto the sheet, output the sentence "The paper is too small." instead.
Sample Input
1 2 3 4 9 4 1 2 3 4 8 3 1 2 3 4 5 5 3 3 3 3 10 10 0 0 0 0 0 0
Sample Output
The minimum number of cuts is 2. The minimum number of cuts is 1. The paper is too small. The minimum number of cuts is 10.
Source
题目大意:在E×F的纸上打印A×B张C×D大小的卡片。
思路:首先枚举卡片的放置方式,就两种方式,C×D或者D×C,然后枚举A×B在纸上的放置方式,(A×B或者B×A)。
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif
#define SI(a) scanf("%d", &(a))
#define SDI(a, b) scanf("%d%d", &(a), &(b))
#define S64I(a) scanf(iform, &(a))
#define SS(a) scanf("%s", (a))
#define SDS(a, b) scanf("%s%s", (a), (b))
#define SC(a) scanf("%c", &(a))
#define PI(a) printf("%d\n", (a))
#define PS(a) puts(a)
#define P64I(a) printf(oform, (a))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define MSET(a, b) (memset((a), (b), sizeof(a)))
#define Mid(L, R) ((L) + ((R) - (L))/2)
#define Abs(a) ((a) >= 0 ? (a) : -(a))
#define REP(i, n) for(int (i)=0; (i) < (n); (i)++)
#define FOR(i, a, n) for(int (i)=(a); (i) <= (n); (i)++)
const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const int maxn = 1000 + 20;
int main() {
int a, b, c, d, e, f;
while(scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) != EOF
&& a && b && c && d && e &&f) {
int ans = INF;
int ta, tb;
ta = a * c;
tb = b * d;
if(ta<=e && tb<=f) {
int tans = 0;
if(ta < e) tans += 1;
if(tb < f) tans += 1;
tans += a * b - 1;
ans = min(ans, tans);
}
if(ta<=f && tb<=e) {
int tans = 0;
if(ta < f) tans += 1;
if(tb < e) tans += 1;
tans += a * b - 1;
ans = min(ans, tans);
}
ta = a * d;
tb = b * c;
if(ta<=e && tb<=f) {
int tans = 0;
if(ta < e) tans += 1;
if(tb < f) tans += 1;
tans += a * b - 1;
ans = min(ans, tans);
}
if(ta<=f && tb<=e) {
int tans = 0;
if(ta < f) tans += 1;
if(tb < e) tans += 1;
tans += a * b - 1;
ans = min(ans, tans);
}
if(ans == INF) {
printf("The paper is too small.\n");
} else {
printf("The minimum number of cuts is %d.\n", ans);
}
}
return 0;
}