Kattis-A Towering Problem

文章讲述了负责艺术展览的人必须重新组织一位著名极简主义雕塑家的作品,这些作品由不同大小的方块堆叠成塔状。由于运输过程中的疏忽,雕塑被随意放置,现在需要根据每组六个方块的两个塔的总高度信息来恢复原布局。给定每个方块和塔的高度,需要编写算法确定每个塔的正确顺序。
摘要由CSDN通过智能技术生成

题目所述基本内容

You’ve been put in charge of an art exhibit from the famous minimalist sculptor J (even his name is minimalist!). J’s work involves the careful layout of vertically dispositioned orthogonal parallelpipeds in a set of tapering obelisks — in other words, he puts smaller boxes on top of larger boxes. His most recent triumph is called “2 by 3’s Decreasing,” in which he has various sets of six boxes arranged in two stacks of three boxes each. One such set is shown below:

J has sent you the art exhibit and it is your job to set up each of the six-box sets at various locations throughout the museum. But when the sculptures arrived at the museum, uncultured barbarians (i.e., delivery men) simply dropped each set of six boxes on the floor, not realizing the aesthetic appeal of their original layout. You need to reconstruct each set of two towers, but you have no idea which box goes on top of the other! All you know is the following: for each set of six, you have the heights of the two towers, and you know that in any tower the largest height box is always on the bottom and the smallest height box is on the top. Armed with this information, you hope to be able to figure out which boxes go together before tomorrow night’s grand opening gala. 

输入输出样例

Input

The input consists of eight positive integers. The first six represent the heights of the six boxes. These values will be given in no particular order and no two will be equal.

The last two values (which will never be the same) are the heights of the two towers.

All box heights will be ≤100 and the sum of the box heights will equal the sum of the tower heights.

Output

Output the heights of the three boxes in the first tower (i.e., the tower specified by the first tower height in the input), then the heights of the three boxes in the second tower. Each set of boxes should be output in order of decreasing height. Each test case will have a unique answer.

Sample Input 1Sample Output 1
12 8 2 4 10 3 25 14
12 10 3 8 4 2
Sample Input 2Sample Output 2
12 17 36 37 51 63 92 124
63 17 12 51 37 36

代码

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define Num 8

bool GreaterSort(int a, int b)
{
	return (a > b);
}

int main() {
	vector<int>arr(8);
	vector<int>result;
	int time = 0;
	int temp = 0;
	for (int i = 0; i < Num; i++) {
		cin >> temp;
		arr[i] = temp;
	}
	sort(arr.begin(), arr.begin() + Num-2, GreaterSort);
	for (int i = 0; i < Num-2; i++) {
		for (int j = i + 1; j < Num-2; j++) {
			for (int k = j + 1; k < Num-2; k++) {
				if (arr[i] + arr[j] + arr[k] == arr[6]) {
					result.push_back(arr[i]);
					result.push_back(arr[j]);
					result.push_back(arr[k]);
				}
			}
		}
	}
	for (int i = 0; i < Num - 2; i++) {
		time = 0;
		for (int j = 0; j < 3; j++) {
			if (arr[i] != result[j]) {
				time++;
				if (time == 3) {
					result.push_back(arr[i]);
				}
			}
		}
	}
	for (int i = 0; i < Num-2; i++) {
		cout << result[i] << " ";
	}
	return 0;
}

结束语

好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个AC梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值