Box

本文介绍了一道关于通过裁剪和折叠纸张形成指定尺寸立方体的算法题。通过对不同情况的分类讨论,利用C++实现了有效的解决方案。




题意:给你一张w*h大小的纸,问经过裁剪和折叠后能不能形成一个a*b*c的立方体

解题思路:分类讨论


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>
#include <ctime>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;

int a[3], w, h;

bool check(int a, int b, int c)
{
	int x = b + c << 1, y = a + (c << 1);
	if ((x <= w && y <= h) || (x <= h && y <= w)) return true;
	x = a + c, y = a + c + 3 * b;
	if ((x <= w && y <= h) || (x <= h && y <= w)) return true;
	x = a + b + c, y = a + c + (b << 1);
	if ((x <= w && y <= h) || (x <= h && y <= w)) return true;
	return false;
}

int main()
{
	while (~scanf("%d%d%d%d%d", &a[0], &a[1], &a[2], &w, &h))
	{
		int flag = 0;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (j == i) continue;
				for (int k = 0; k < 3; k++)
				{
					if (k == i || k == j) continue;
					if (check(a[i], a[j], a[k])) flag = 1;
				}
			}
		}
		if (flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值