option=com_onlinejudge&Itemid=8&page=show_problem&category=457&problem=375&mosmsg=Submission+received+with+ID+14034251">题目链接

题意:给出n,代表所要用积木搭建的总体的底面积的边长,然后分别给出正视图和右视图。要你求出搭建都要形状的最小木块数量和最小木块数量和最大木块数量的差值。

思路:事实上题目就是要你求出最小木块数和最大木块数。我们能够分开求解。 

首先对于最小木块数,要想用最少的立方体搭建,那就意味着正视图中的每一竖立方体的高度最好都要被右视图中的高度所利用到。所以我们以正视图为基准,正视图须要的立方体总数加上側视图存在无法利用正视图的数量。就是最少须要的立方体数。

其次对于最大木块数。我们也以正视图为基准,再对比右视图,一层一层计算木块数,尽量每一层都能铺满,然后累加上去就是最大的木块数了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAXN = 10; int a[MAXN], b[MAXN], num1[MAXN], num2[MAXN];
int n; int getMin() {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
for (int i = 1; i <= n; i++) {
num1[a[i]]++;
num2[b[i]]++;
}
int sum = 0;
for (int i = 1; i <= MAXN; i++)
sum += max(num1[i], num2[i]) * i;
return sum;
} int getMax() {
int cnt1, cnt2, sum = 0;
while (1) {
cnt1 = 0;
for (int i = 1; i <= MAXN; i++)
if (a[i]) {
cnt1++;
a[i]--;
}
cnt2 = 0;
for (int i = 1; i <= MAXN; i++)
if (b[i]) {
cnt2++;
b[i]--;
}
if (!cnt1 && !cnt2) break;
sum += cnt1 * cnt2;
}
return sum;
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &b[i]);
int Min = getMin();
int Max = getMax();
printf("Matty needs at least %d blocks, and can add at most %d extra blocks.\n", Min, Max - Min);
}
return 0;
}

UVA434 - Matty&#39;s Blocks的更多相关文章

  1. UVA - 434 Matty&#39;s Blocks

    题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的 ...

  2. UVA434 - Matty's Blocks

    题意:已知前视图和右视图,求最少需要几个正方体以及至多可以再增加几个正方体. 分析:先对于最小木块数,要想用最少的立方体搭建,那就意味着前视图中的每一竖立方体的高度最好都要被右视图中的高度所利用到.所 ...

  3. 【UVA】434-Matty&#39;s Blocks

    一道非常easy想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成相应的视图,以及最多还能加几块正方体. 求最多加入事实上就是求出最多的正方体数减去最少的,主要就是最少的不好求. 一開始各种模 ...

  4. bc.34.B.Building Blocks(贪心)

    Building Blocks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free data blocks. Create more free space in thin pool or use dm.min_free_space option to change behavior

    问题: 制作镜像的时候报错 devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 1 ...

  6. Deal with relational data using libFM with blocks

    原文:https://thierrysilbermann.wordpress.com/2015/09/17/deal-with-relational-data-using-libfm-with-blo ...

  7. Moodle插件开发——Blocks(版块)

    前提: 1)     基于Moodle3.0,要求Moodle版本高于2.0 2)     PHP编程基础:语言的了解和开发工具使用 有经验的开发人员和那些只是想程序员的参考文本应参阅附录A. 1.  ...

  8. 转 Alert.log shows No Standby Redo Logfiles Of Size 153600 Blocks Available

    http://blog.itpub.net/23135684/viewspace-703620/ Alert.log shows No Standby Redo Logfiles Of Size 15 ...

  9. CODEFORCEs 621E. Wet Shark and Blocks

    E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. android用于打开各种文件的intent

    import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.n ...

  2. cocostudio——js 3 final控件事件

    近期试用了下cocos ide,然后引擎用的cocos2dx js 3 final,须要build runtime一下,以下是cocos studio相关的一些事件: 加入事件侦听: // butto ...

  3. UVA796- Critical Links(无向图中的桥梁)

    题目链接 题意: 给出一个无向图,按顺序输出桥 思路:求出全部的桥,然后按顺序输出就可以 代码: #include <iostream> #include <cstdio> # ...

  4. loj1201(最大独立集)

    传送门:A Perfect Murder 题意:有一群苍蝇,之间有一些是朋友关系,如果杀了一只苍蝇,那么它的朋友们都会有警惕性,再也杀不了这些朋友了,问最多能杀多少只苍蝇. 分析:根据朋友性连边,最多 ...

  5. malloc函数的一种简单的原理性实现

    malloc()是C语言中动态存储管理的一组标准库函数之一.其作用是在内存的动态存储区中分配一个长度为size的连续空间.其参数是一个无符号整形数,返回值是一个指向所分配的连续存储域的起始地址的指针 ...

  6. extern int *a与extern int a[]

    extern int *a与int a[] Table of Contents 1. 问题: 2. 解答: 1 问题: 以下的声明取自某个源文件: int a[10]; int *b=a; 但在还有一 ...

  7. Qt调用word 例子

    Qt调用word 例子 Getting Microsoft Word Object to SaveAs #include <QtGui> #include <QAxObject> ...

  8. hdu 4007 Dave (2011年大连ACM网络赛)

    题意:给定正方形的边长 r ,在平面内寻找正方形可以圈住的点的最大的个数. 分析:先对点排序,然后固定一条边,再平移另一条垂直边,得到点的个数,最后比较大小即可. 注意:不包含正方形倾斜的情况! // ...

  9. session深入解读

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:尽管session机制在web应用程序中被採用已经非常长时间了.可是仍然有非常多人不清楚 ...

  10. Git管理工具对照(GitBash、EGit、SourceTree)

    Git管理工具对照(GitBash.EGit.SourceTree) GitBash是採用命令行的方式对版本号进行管理,功能最为灵活强大,可是由于须要手动输入希望改动的文件名称,所以相对繁琐. EGi ...