UVA434 - Matty's Blocks
题意:给出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's Blocks的更多相关文章
- UVA - 434 Matty's Blocks
题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的 ...
- UVA434 - Matty's Blocks
题意:已知前视图和右视图,求最少需要几个正方体以及至多可以再增加几个正方体. 分析:先对于最小木块数,要想用最少的立方体搭建,那就意味着前视图中的每一竖立方体的高度最好都要被右视图中的高度所利用到.所 ...
- 【UVA】434-Matty's Blocks
一道非常easy想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成相应的视图,以及最多还能加几块正方体. 求最多加入事实上就是求出最多的正方体数减去最少的,主要就是最少的不好求. 一開始各种模 ...
- bc.34.B.Building Blocks(贪心)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 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 ...
- Deal with relational data using libFM with blocks
原文:https://thierrysilbermann.wordpress.com/2015/09/17/deal-with-relational-data-using-libfm-with-blo ...
- Moodle插件开发——Blocks(版块)
前提: 1) 基于Moodle3.0,要求Moodle版本高于2.0 2) PHP编程基础:语言的了解和开发工具使用 有经验的开发人员和那些只是想程序员的参考文本应参阅附录A. 1. ...
- 转 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 ...
- 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 ...
随机推荐
- 彻底删除"提示删除文件和目录"时出错的文件或目录
当删除文件是出现上图时 能够用以下的方法删除文件 策略一:系统大法 第一招 进程帮你搞定 很多时候乱码文件名称里的文件是explorer.exe进程联系在一起的. 假设要删除的话能够这样:首先命令 ...
- Linux温馨提示1--安装U板块和Windwos划分
一.安装U盘 现在我用Ubuntu12.04在插入U光盘将被直接安装到/media/下, 10:33linc@Linc-Ubuntu:linc$ df -h Filesystem Size Used ...
- MyCAT部署及实现读写分离(转)
MyCAT是mysql中间件,前身是阿里大名鼎鼎的Cobar,Cobar在开源了一段时间后,不了了之.于是MyCAT扛起了这面大旗,在大数据时代,其重要性愈发彰显.这篇文章主要是MyCAT的入门部署. ...
- NSDictionary、NSMutableDictionary基本使用
郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...
- Tomcat在Linux上安装
1. 下载并 安装 tomcat wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.14/bin/apache-tomcat-8.0 ...
- 设计模式之十:观察者模式(Observer)
观察者模式: 在对象之间定义了一种一对多的依赖关系.当一个对象改变它的状态时,全部依赖它的对象会自己主动接收通知并更新自己的状态. Define a one-to-many dependency be ...
- HDU 4916 树分治
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- spring原拦截器配置与新命名空间mvc:interceptors配置拦截器对照与注意事项
原先,我们是这么配置拦截器的 <bean id="openSessionInViewInterceptor"class="org.springframework.o ...
- SSM框架整合( Spring 、 SpringMVC 和 Mybatis )
1.基本概念 1.1.Spring Spring 是一个开源框架, Spring 是于 2003 年兴起的一个轻量级的 Java 开发框架,由 Rod Johnson 在其著作 Expert O ...
- SWT的TableVierer的使用一
1,简单显示,表格的式样见注释中的内容 import org.eclipse.jface.viewers.TableViewer;import org.eclipse.swt.SWT;import o ...