LA 4636 Cubist Artwork(贪心)

185 篇文章 0 订阅
65 篇文章 0 订阅

International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended to amuse visitors, who will be curious how the shape of the collection of cubes changes when it is seen from the front and the sides.

The artwork is a collection of cubes with edges of one foot long and is built on a flat ground that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes of the artwork must be either put on the ground, fitting into a unit square in the grid, or put on another cube in the way that the bottom face of the upper cube exactly meets the top face of the lower cube. No other way of putting cubes is possible.

You are a member of the judging committee responsible for selecting one out of a plenty of artwork proposals submitted to the competition. The decision is made primarily based on artistic quality but the cost for installing the artwork is another important factor. Your task is to investigate the installation cost for each proposal. The cost is proportional to the number of cubes, so you have to figure out the minimum number of cubes needed for installation.

Each design proposal of an artwork consists of the front view and the side view (the view seen from the right-hand side), as shown in Figure 1.

\epsfbox{p4636a.eps}
Figure 1: An example of an artwork proposal

The front view (resp., the side view) indicates the maximum heights of piles of cubes for each column line (resp., row line) of the grid.

There are several ways to install this proposal of artwork, such as the following figures.

\epsfbox{p4636b.eps}

In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of height three in the right figure plays the roles of two such piles in the left one.

Notice that swapping columns of cubes does not change the side view. Similarly, swapping rows does not change the front view. Thus, such swaps do not change the costs of building the artworks. For example, consider the artwork proposal given in Figure 2.

\epsfbox{p4636c.eps}
Figure 2: Another example of artwork proposal

An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown in the following figure, which can be obtained by exchanging the rightmost two columns of the optimal installation of the artwork of Figure 1.

\epsfbox{p4636d.eps}

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows.


w d
h
1 h2 ... hw
h'1 h'2 ... h'd


The integers w and d separated by a space are the numbers of columns and rows of the grid, respectively. You may assume1$ \le$w$ \le$10 and 1$ \le$d$ \le$10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integershi(1$ \le$hi$ \le$20, 1$ \le$i$ \le$w) in the second line give the front view, i.e., the maximum heights of cubes per each column line, ordered from left to right (seen from the front). The integersh'i(1$ \le$h'i$ \le$20, 1$ \le$i$ \le$d ) in the third line give the side view, i.e., the maximum heights of cubes per each row line, ordered from left to right (seen from the right-hand side).

Output

For each dataset, output a line containing the minimum number of cubes. The output should not contain any other extra characters.

You can assume that, for each dataset, there is at least one way to install the artwork.

Sample Input

5 5 
1 2 3 4 5 
1 2 3 4 5 
5 5 
2 5 4 1 3 
4 1 5 3 2 
5 5 
1 2 3 4 5 
3 3 3 4 5 
3 3 
7 7 7 
7 7 7 
3 3 
4 4 4 
4 3 4 
4 3 
4 2 2 4 
4 2 1 
4 4 
2 8 8 8 
2 3 8 3 
10 10 
9 9 9 9 9 9 9 9 9 9 
9 9 9 9 9 9 9 9 9 9 
10 9 
20 1 20 20 20 20 20 18 20 20 
20 20 20 20 7 20 20 20 20
0 0

Sample Output

15 
15 
21 
21 
15 
13 
32 
90 
186


题意:高中数学经常做的题,给你三视图的正视图和侧视图,问你最少有多少个立方体。


分析:很弱的一道题然而一开始想错了,如果i行和j列的最大高度相等的话那么在(i,j)位置放一摞这个高度的立方体就可以了,所以统计每种高度立方体出现的次数,注意要行和

列分开统计,最后每种取行或列的最大值就可以了。


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int w,d,tot,x,a[21],b[21];
int main()
{
	cin.sync_with_stdio(false);
	while(cin>>w>>d && w && d)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		int ans = 0;
		for(int i = 1;i <= w;i++)
		{
			cin>>x;
			a[x]++;
		} 
		for(int i = 1;i <= d;i++) 
		{
			cin>>x;
			b[x]++;
		} 
		for(int i = 1;i <= 20;i++) ans += i*max(a[i],b[i]); 
		cout<<ans<<endl;
	}
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用[1]:在目前的文献中,较少的预测ML算法经过训练和测试后将结果与以前的研究进行比较,例如(Adamovic et al., 2017; Johnson et al., 2017; Kannangara et al., 2017)。在这些研究中,不同的机器学习技术的真正多功能性和优势或局限性仍然未知。引用[2]:DNN的核心思想不仅是学习输入和输出之间的非线性映射,而且是学习数据的底层结构(Karhunen et al., 2015)。DNN模型使用反向误差传播算法从训练数据中学习模式,其中,来自输出的误差或反馈信号将向后传播,以调整神经网络权重并使最终输出的误差最小(Chollet and Allaire, 2018)。DNN的结构包括输入,隐藏和输出层。引用[3]:基于机器学习模型的预测结果有助于越南的综合固体废弃物管理行动计划的规划、设计和实施。本研究的局限性体现在数据集的异质性,如越南下级行政部门缺乏有效数据。基于此,当未来能够获取更多的可靠数据时,可以更新和重新训练机器学习预测模型。 问题: 什么是机器学习cubist? 回答: 在提供的引用中,并没有提到机器学习cubist的具体定义或描述。引用[1]提到了一些机器学习算法的比较,但没有提到cubist。引用[2]提到了DNN(深度神经网络)的核心思想和结构,但没有提到cubist。引用[3]讨论了基于机器学习模型的预测结果在固体废弃物管理中的应用,但同样没有提到cubist。因此,根据提供的引用内容,无法回答关于机器学习cubist的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值