Box(gym 101630 B)

原文地址B题

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?
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 10 8 .
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.

INPUT
1 2 3
6 5
OUTPUT
Yes

INPUT
1 2 3
5 5
OUTPUT
No

INPUT
1 1 1
10 2
OUTPUT
YES

题意:给出一个w*h的方格纸,问可以通过剪切变成一个a*b*c的长方体吗

思路:在给出的11种可能的正方体拼法中,按照长和宽分类,有4*3,3*4,2*5的,找出这3种其中的一种拼法,求出最少满足的方格纸的大小,在将abc分别可能的6种情况暴力搜索就可以。具体看图:

AC代码:

/***
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define PI acos(-1)
const int mod=1e9+7;
const int M=2e5 + 10;
int check(int a,int b,int c,int w,int h)
{
    if(2*a+2*c<=w&&2*a+b<=h||2*a+2*c<=h&&2*a+b<=w)
        return 1;
    else if(a+b+c<=w&&2*a+b+c<=h||a+b+c<=h&&2*a+b+c<=w)
        return 1;
    else if(a+b<=w&&a+b+3*c<=h||a+b<=h&&a+b+3*c<=w)
        return 1;
    return 0;
}
int main()
{
    //freopen("//home//acm//桌面//in","r",stdin);
    int a,b,c,w,h;
    cin>>a>>b>>c>>w>>h; 
    if(check(a,b,c,w,h)||check(a,c,b,w,h)||check(b,a,c,w,h)||check(b,c,a,w,h)||check(c,a,b,w,h)||check(c,b,a,w,h))
        cout<<"Yes"<<endl;//调换a,b,c后的六种情况
    else
        cout<<"No"<<endl;
    return 0;
}
发布了350 篇原创文章 · 获赞 715 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/99951495