列表

详情


NC54380. Box

描述

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.

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?

输入描述

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.

输出描述

Print “Yes” if it is possible to cut a box a × b × c out of a cardboard of size w × h. Print “No” otherwise.

示例1

输入:

1 2 3
6 5

输出:

Yes

示例2

输入:

1 2 3
5 5

输出:

No

示例3

输入:

1 1 1
10 2

输出:

Yes

说明:

There are 11 different nets of a cube, ignoring rotations and mirror images.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 5ms, 内存消耗: 504K, 提交时间: 2020-10-21 18:42:21

#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,w,h;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if (a>b) swap(a,b);
	if (a>c) swap(a,c);
	if (b>c) swap(b,c);
	scanf("%d%d",&w,&h);
	if (w>=c+2*a&&h>=2*a+2*b||h>=c+2*a&&w>=2*a+2*b
	  ||w>=b+2*a&&h>=2*a+2*c||h>=b+2*a&&w>=2*a+2*c
	  ||w>=a+c&&h>=a+c+3*b||h>=a+c&&w>=a+c+3*b
	  ||w>=a+b&&h>=a+b+3*c||h>=a+b&&w>=a+b+3*c
	  ||w>=b+c&&h>=b+c+3*a||h>=b+c&&w>=b+c+3*a)
	  printf("Yes\n");
	else
	  printf("No\n");
}

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 504K, 提交时间: 2020-10-06 15:29:47

#include<iostream>
#include<algorithm>
using namespace std;
int w,h;
bool check(int a,int b,int c){
	if(2*b+2*c<=h&&2*c+a<=w||2*b+2*c<=w&&2*c+a<=h) return 1;
	else if(b+2*c+a<=w&&a+b+c<=h||b+2*c+a<=h&&a+b+c<=w) return 1;
	else if(3*a+b+c<=w&&b+c<=h||3*a+b+c<=h&&b+c<=w) return 1;
	return 0;
} 
int main(){
	int a,b,c;
	cin>>a>>b>>c>>w>>h;
	if(check(a,b,c)||check(a,c,b)||check(c,a,b)||check(c,b,a)||check(b,c,a)||check(b,a,c)) cout<<"Yes";
	else cout<<"No";
	return 0;
} 

上一题