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. ios 上拉载入下拉刷新Dome

    为练手写了一个小的上拉载入很多其它下拉刷新的小的Dome . 没有太多的技术含量,仅仅是作为新手的启示用.是上一篇下拉载入的扩展.先看一下那个再看这个就easy非常多. Dome下载:http://d ...

  2. hdu3062(two-sat)

    传送门:Party 题意:有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席.在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在 ...

  3. UVa 213 Message Decoding(World Finals1991,串)

     Message Decoding  Some message encoding schemes require that an encoded message be sent in two part ...

  4. Ubuntu12.04password正确 入口的桌面(测试的恢复正常)

    举行了两次会议ubuntu输入password正确,但高考制度,输入password后,跳转看接口 后来又返回到登录界面,这个周期已经输入password. 解决方案:1.输入tty下         ...

  5. Windows下安装MySQLdb, Python操作MySQL数据库的增删改查

    这里的前提是windows上已经安装了MySQL数据库,且配置完成,能正常建表能操作. 在此基础上仅仅需安装MySQL-python-1.2.4b4.win32-py2.7.exe就ok了.仅仅有1M ...

  6. 2014鞍山现场赛C题HDU5072(素筛+容斥原理)

    Coprime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  7. vs2008+opencv2.4.9 +win7X64位系统 2.

    小编用自身血淋淋的例子,来给大家做个参考,共耗时近2天时间,终于屈服于安装vs2010,然后配置成功了.但是在这个配置成功后,我终于发现了我08配置不成功的原因,写下心得,供各位参考 1.准备工具 v ...

  8. Android Studio使用心得 - 简单介绍与环境配置

    FBI Warning:欢迎转载,但请标明出处:http://blog.csdn.net/codezjx/article/details/38544823,未经本人允许请勿用于商业用途.感谢支持! 关 ...

  9. Linux下精确控制时间的函数

    Linux下精确控制时间的函数 在测试程序接口运行时间的时候,常用time,gettimeofday等函数,但是这些函数在程序执行的时候是耗费时间的,如果仅仅测试时间还行,但是如果程序中用到时间控制类 ...

  10. 使用OGG&quot;Loading data from file to Replicat&quot;的方法应该注意的问题:replicat进程是前台进程

    使用OGG的 "Loading data from file to Replicat"的方法应该注意的问题:replicat进程是前台进程 因此.最好是在vncserver中调用该 ...