盒子 Box

2023-12-25 06:44:28

UVa1587

?思路:

1.输入每个面的长宽并将每个面较长的一边放在前面

2.判断是否存在三对面分别相等

3.判断是否存在三组四棱相等

#include <stdio.h>
#include <stdlib.h>
#define maxn 100

int cmp(const void* e1, const void* e2)
{
	return (int)(*(double*)e1 - *(double*)e2);
}

int main()
{
	double h[maxn] = { 0 };
	double w[maxn] = { 0 };
	int sign[6] = { 0 };//标记
	for (int i = 0; i < 6; i++)
	{
		scanf("%lf %lf", &h[i], &w[i]);
		if (h[i] < w[i])//把比较大的放前面
		{
			double tmp = h[i];
			h[i] = w[i];
			w[i] = tmp;
		}
	}
	//判断是否存在三组面两两相等
	for (int i = 0; i < 6; i++)
	{
		if (sign[i] == 1)
		{
			continue;
		}
		for (int j = i + 1; j < 6; j++)
		{
			if (h[i] == h[j])
			{
				if (w[i] == w[j])
				{
					sign[i] = 1;
					sign[j] = 1;
					break;
				}
			}
		}
	}
	for (int i = 0; i < 6; i++)
	{
		if (sign[i] != 1)
		{
			printf("NO\n");
			return 0;
		}
	}
	//判断是否存在三组棱4条相等
	double h_w[maxn] = { 0 };
	for (int i = 0; i < 6; i++)
	{
		h_w[i] = h[i];
	}
	for (int i = 0; i < 6; i++)
	{
		h_w[i + 6] = w[i];
	}
	qsort(h_w, 12, sizeof(double), cmp);//排序,便于判断每组四条棱是否相等
	for (int i = 0; i < 12; )
	{
		if (h_w[i] == h_w[i + 1] && h_w[i + 1] == h_w[i + 2] && h_w[i + 2] == h_w[i + 3])
		{
			i = i + 4;
		}
		else
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");

	return 0;
}

文章来源:https://blog.csdn.net/cookies_s_/article/details/135189122
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。