题意:给你一张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;
}

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

被折叠的 条评论
为什么被折叠?



