描述:

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.

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.

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.

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.

输入:

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
h1 h2 ... hw
h1' h2' ... hd'

The integers w and d separated by a space are the numbers of columns and rows of the grid, respectively. You may assume 1 <= w <= 10 and 1 <= d <= 10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integers hi (1 <= hi <= 20, 1 <= i <= 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 integers hi' (1 <= hi' <= 20, 1 <= i <= 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).

输出:

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.

样例输入:

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

复制

样例输出:

15
15
21
21
15
13
32
90
186

单纯的数学规律吧,只能记住了。

#include<iostream>
using namespace std;
int main()
{int sum1,sum2;while(cin>>sum1>>sum2){if(sum1==0&&sum2==0)break;int bns[21]={0},ans[21]={0};for(int n=0;n<sum1;n++){int number;cin>>number;bns[number]++;}for(int n=0;n<sum1;n++){int number;cin>>number;ans[number]++;}int dis=0;for(int n=1;n<=20;n++)dis+=n*max(bns[n],ans[n]);cout<<dis<<endl;}return 0;
}

Cubist Artwork相关推荐

  1. UVALive - 4636 Cubist Artwork——思维

    把正视图用体积为1的小格子先填上一层,如果把这些列重排一下恰好能构成右视图,那么当前的填充方法就是最优的,基于这个思想我们对两个数列从大到小排序后瞎搞就可以了 #include <bits/st ...

  2. UVA1445 Cubist Artwork

    链接 题解 光看正视图的话,最省积木的搭建方式肯定是把所有积木搭成一面墙,厚度为1,所耗的积木数就是每个位置上的积木高度之和. 考虑如何多快好省地构造出侧视图,看到样例我们就可以想到,我可以把这面墙里 ...

  3. 《算法竞赛入门经典——训练指南》第一章相关内容

    #<算法竞赛入门经典--训练指南>第一章相关内容 希望各位大牛能指导! 红色为已经做了的...黄色背景是还有不懂地方,希望在年前能刷完第一章啊.... 更新版.google上貌似又加了ex ...

  4. PS油画特效插件AKVIS Artwork for mac

    AKVIS ArtWork Plugin for Mac是一款运行在Mac平台上的PS油画特效插件,AKVIS ArtWork Plugin Mac版可以将照片自动转换为绘画,提供油画.水彩画.水粉画 ...

  5. cadence SPB17.4 - allegro - Artwork will be rounded down

    cadence SPB17.4 - allegro - Artwork will be rounded down 前言 出装配图时,弹出如下警告对话框 具体提示信息如下: -------------- ...

  6. artwork will be rounded down because......

    cadence SPB17.4 - allegro - Artwork will be rounded down

  7. allegro artwork设置和颜色设置的导入导出

    allegro artwork设置和颜色设置的导入导出 2013-07-12 13:17:36 分类: WINDOWS allegro 使用artwork出gerber的关键就是每张底片的颜色输出,所 ...

  8. Cadence Allegro Artwork光绘文件参数设置

    Allegro 输出Gerber文件之前要进行Artwork参数设置, 其中包括外形(OUTLIINE),助焊(PASTEMASK),阻焊(SOLDERMASK),钻孔(DRILL),丝印(SILKS ...

  9. Cadence Allegro PCB设计88问解析(二) 之 Allegro中Artwork层复用(导入导出)

    一个学习信号完整性仿真的layout工程师 因为每个人的习惯不同,所以在平常的设计中查看的光绘层是不同的,有助于自己快速的layout.但是在每次拿到别人的板子去改版或者重新设计时,都要添加自己习惯的 ...

最新文章

  1. java 泛型多重限制_Java泛型:有界类型参数中的多重继承
  2. java 第三方代码_Java:如何使用第三方库?
  3. 关于所谓的穷人富人幸福论
  4. python手机编译器可以干什么_Python是什么?Python学习用哪些编译器?
  5. afm原子力分析软件_牛津仪器发布全新大样品原子力显微镜Jupiter XR
  6. 可用性目标概念化(摩西十戒)
  7. 复数正弦波 matlab,为什么正弦,反正弦函数计算结果会出现复数?
  8. security面试_41 道 Spring Boot 面试题,帮你整理好了!
  9. 比较简单搞定S60的签名
  10. Halcon实现Otsu最大类间方差法
  11. iOS H264编码及解码
  12. 常用基本初等函数的求导公式推导
  13. Skype、MSN/Live Messenger、Lync全面整合
  14. 网络SSID是什么意思
  15. java poc_无回显命令执行PoC编写指南(Apache Shiro Java反序列化)
  16. Matlab学习手记——非线性拟合方法:压缩因子粒子群算法
  17. Java后台生成多个Excel并用Zip打包后(可以将excel文件放置到不同的目录)下载
  18. 应届毕业生不想应聘上班,一心想独自创业,有什么好的项目推荐?
  19. 微信小程序获取用户信息-头像、昵称......
  20. 关于JavaScript的一些使用心得

热门文章

  1. 紫外线杀菌装置:过流式Photoscience紫外线杀菌器
  2. Android 类似未读短信图标显示数字效果的分析
  3. IP地址的划分及其范围
  4. FOC控制中Clark/iClark和Park/iPark变换及matpoltlib仿真
  5. Kubernetes CKA认证运维工程师笔记-Docker快速入门
  6. 基于C++控制台(Windows平台)的一个吃豆人小游戏
  7. H5和C3新特性(完整版)
  8. 电脑问题处理篇4:解决华硕电脑“ASUS Battery Health Charging”软件界面呈现灰色不能选择充电模式的问题
  9. 阿里云基础认证(ACA - Alibaba Cloud Certification Associate)
  10. 疯狂的程序员-第二十三章