10326 Paper cutting
时间限制:1000MS 内存限制:65535K
提交次数:1 通过次数:0
题型: 编程题 语言: G++;GCC
Description
You are now given a large sheet of paper, which is in rectangle shape. Now you are asked to cut another rectangle from the given paper. Your task is to decide whether is it possible to cut the rectangle from the given paper.
输入格式
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case consists of a single line. The line contains exactly four integer numbers separated by spaces: A, B, X and Y. A and B indicate the dimensions of the given paper, X and Y are the dimensions of the requested rectangle (1 <= A,B,X,Y <= 50000).
输出格式
Your task is to determine whether it is possible to cut the rectangle from the given paper. If so, you are to print one line with the sentence "Cutting is possible." Otherwise print the sentence " Cutting is impossible ".
输入样例
2 10 10 8 8 8 8 10 10
输出样例
Cutting is possible. Cutting is impossible.
08scau校赛题目。题目看上去很简单,但如果没有考虑清楚很可能wa很多次。
第一眼看上去只需要将,所给矩形(a,b边)和要剪出的矩形(x,y边),只需把令(小边)a>=x,(大边)b>=y这两个条件满足就可以了,但你如果这么想,恭喜你wa了。
因为还有一种极端情况并没有考虑,就是如果你将所给矩形斜着剪,那么就可以剪出比平放着剪更大的矩形。
为了叙述方便,我们可以把问题简化为,要剪的矩形能不能放入所给矩形。
边的关系总共有4种。
1 a>=x&&b>=y 那么直接平放进去,完全可以放得进
2 a>=x&&b<y 这种情况需要仔细考虑**
3 a<x&&b>=y 这种情况需要仔细考虑**
4 a<x&&b<y 两条边都比所给矩形要大,一定不可以
上面2,3情况需要,它可以将矩形斜着放入所给矩形中
引用别人的图,可以看到,可以恰好放入的情况如图所示,那么怎么求它的极端情况是否能放入呢,
我们将b与y形成的角度设为k,范围(0,90)极端情况如上图所示。y*sin(k)+x*cos(k)=a && y*cos(k)+x*sin(k)=b
那么假如将y缩小或者x缩小,上述条件就变为y*sin(k)+x*cos(k)<a && y*cos(k)+x*sin(k) <b,可以去尝试自己画画图,就是固定一端两个端点,再将边缩短就可以了,题目只需要找到一个角度k符合y*sin(k)+x*cos(k)<=a && y*cos(k)+x*sin(k) <=b 就可以放的下,如果找不到这样的k,那么就放不下。(0和90就是平放的情况)
那么最后一个问题,我们应该去如何确立精度呢,可以设置0.1或0.2的精度,0.1勉强过,0.2比较好,这是用暴力去做的题目
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string.h>
#define pi acos(-1.0)
using namespace std;
int a,b,x,y;
int pd()
{
double k ,g;
for(k=0;k<=90;k+=0.1)
{
g=k*pi/180.0;
if(y*sin(g)+x*cos(g)<=a&&y*cos(g)+x*sin(g)<=b) return 1;
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d%d",&a,&b,&x,&y);
if(a>b) swap(a,b);
if(x>y) swap(x,y);
if(pd()) printf("Cutting is possible.\n");
else printf("Cutting is impossible.\n");
}
}
同时poj1380就是小矩形放大矩形的原题