ACM ICPC 2017–2018, NEERC – Northern Eurasia Finals Problem B. 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.
在这里插入图片描述
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种,一共是九种,判断一下就好啦。

  1. t1 = 2a + b, t2 = 2a + 2*c;
  2. t1 = 2a + c, t2 = 2a + 2*b;
  3. t1 = 2b + a, t2 = 2b + 2*c;
  4. t1 = 2c + a, t2 = 2c + 2*b;
  5. t1 = 2b + c, t2 = 2b + 2*a;
  6. t1 = 2c + b, t2 = 2c + 2*a;
  7. t1 = 3*a + b + c, t2 = b + c;
  8. t1 = 3*b + a + c, t2 = a + c;
  9. 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值