NC54380. Box
描述
输入描述
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
说明:
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; }