Bella is working in a factory that produces boxes. All boxes are in a shape of rectangular parallelepipeds.
A net of the corresponding parallelepiped is cut out of a flat rectangular piece of cardboard of size w ×h.
This net is a polygon with sides parallel to the sides of the rectangle of the cardboard. The net is bent
along several lines and is connected along the edges of the resulting parallelepiped to form a box. The
net is bent only along the edges of the resulting box.
The first example
The third example
Bella is a software developer and her task is to check whether it is possible to make a box of size a×b×c
out of a cardboard of size w × h. Bella did write a program and boxes are being produced. Can you do
the same?
Input
The first line contains three integers a, b, and c — the dimensions of the box.
The second line contains two integers w and h — the width and the height of the cardboard.
All integers are positive and do not exceed 108.
Output
Print “Yes” if it is possible to cut a box a × b × c out of a cardboard of size w × h. Print “No” otherwise.
Examples
input output
1 2 3
6 5
Yes
1 2 3
5 5
No
1 1 1
10 2
Yes
Note
There are 11 different nets of a cube, ignoring rotations and mirror images.
题解:当时是想的把立体的图形画出来,然后思考如何才能使得剪出来的长最大,剪法大概就是顺着一条边剪下去,如下图1;然后再剪成长最短,如图2的剪法。那么长在这个区间,满足限制条件
1. 2a + 2b ≤ h and b + 2c ≤ w
2. a + c ≤ h and 3b + a + c ≤ w
因为a,b,c没有说明谁是长宽高,所以需要遍历一遍1的情况扩展为6种,2的情况扩展为3种,一共是九种,判断一下就好啦。
- t1 = 2a + b, t2 = 2a + 2*c;
- t1 = 2a + c, t2 = 2a + 2*b;
- t1 = 2b + a, t2 = 2b + 2*c;
- t1 = 2c + a, t2 = 2c + 2*b;
- t1 = 2b + c, t2 = 2b + 2*a;
- t1 = 2c + b, t2 = 2c + 2*a;
- t1 = 3*a + b + c, t2 = b + c;
- t1 = 3*b + a + c, t2 = a + c;
- t1 = 3*c + a + b, t2 = a + b;
这个公式的来法:
1的剪法:顺着红色的剪。至于为什么大佬可以证明一下,蒟蒻的我是画出来的。这两个图就是极端情况了,满足这两个图的条件就OK了。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a,b,c;
ll w,h;
int judge(){
ll t1 = 2*a + b, t2 = 2*a + 2*c;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 2*a + c, t2 = 2*a + 2*b;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 2*b + a, t2 = 2*b + 2*c;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 2*c + a, t2 = 2*c + 2*b;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 2*b + c, t2 = 2*b + 2*a;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 2*c + b, t2 = 2*c + 2*a;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 3*a + b + c, t2 = b + c;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 3*b + a + c, t2 = a + c;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
t1 = 3*c + a + b, t2 = a + b;
if((t1 <= w && t2 <= h) || (t1 <= h && t2 <= w)){
return 1;
}
return 0;
}
int main(){
while(~scanf("%lld%lld%lld",&a,&b,&c)){
scanf("%lld%lld",&w,&h);
if(judge()) printf("Yes\n");
else printf("No\n");
}
return 0;
}