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 ...
随机推荐
- tomcat各版本和jsp、jstl、servlet的依赖关系(转)
Servlet / JSP / Tomcat Version Servlet/ JSP Tomcat 2.5/2.1 6.0.18 2.4/2.0 5.5.27 2.3/1.2 4.1.3 ...
- Android开发周报:Android L默认加密用户数据
Android开发周报:Android L默认加密用户数据 新闻 <iCloud前车之鉴,Android L默认开启加密功能>:iCloud 艳照风波再起,第二波女星照片流出,大量女星的裸 ...
- stripslashes和addslashes的区别
我们在向mysql写入数据时,比如: mysql_query(”update table set `title`=’kuhanzhu’s blog’”); 那就会出错.同asp时一样,数据库都会对单引 ...
- windows server 搭建radius服务器
使用ISA 2004搭建PPTP/L2TP 服务器后,VPN账号是在radius服务器上的,使用window server 2003搭建radius服务器,需要添加组件->internet验证服 ...
- 50个最受网友欢迎的HTML5资源下载列表
完整附件下载地址:http://down.51cto.com/data/413867 附件预览: HTML 5游戏源码精选(共含9个游戏源码) http://down.51cto.com/zt/227 ...
- V5
系统设置--关于手机--版本号点5下--进去开发模式--打开开发选项--打开USB调试.然后在连接第三方助手软件 http://bbs.ztehn.com/thread-19037-1-1.html
- OCP-1Z0-051-题目解析-第30题
30. Evaluate the following CREATE TABLE commands: CREATE TABLE orders (ord_no NUMBER(2) CONSTRAINT o ...
- CCNA CCNP CCIE所有实验名称完整版
实验1:通过Console端口访问Cisco路由器 实验2:通过Telnet访问Cisco路由器 实验3:配置终端服务器 实验4:通过浏览器访问路由器 实验5:模式切换.上下文帮助及查看有关信 ...
- [POJ 3150] Cellular Automaton (矩阵高速幂 + 矩阵乘法优化)
Cellular Automaton Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 3048 Accepted: 12 ...
- NYOJ 45 棋盘覆盖 模拟+高精度
题意就不说了,中文题... 小白上讲了棋盘覆盖,于是我就挖了这题来做. 棋盘覆盖的推导不是很难理解,就是分治的思想,具体可以去谷歌下. 公式就是f(k) = f(k - 1) * 4 + 1,再化解下 ...