UVa LA 4636 Cubist Artwork 难度: 0
题目
题意
积木,有左视图和前视图,问最少几块积木
思路
明显,把前视图视作列,左视图视作行,从大到小排列行和列,如果此时未处理的行列最大值恰巧相等为h,那么就是说在这个新行/列中,恰可以放一个高为h的积木。如果不相等且较大值为h,那么就必须要做一个高为h的积木组,假如h是左视图上的要求,那么要把它放在列长大于等于h的列中掩盖起来,防止前视图中看到这个h高积木,因为前视图看不到这个h高积木。
简而言之,排个序,相同的只加一份,不同的各算一份。
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 1e3 + ;
typedef pair<int, int> Pair;
int n, m;
int a[MAXN], b[MAXN];
int main() {
int T;
//scanf("%d", &T);
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
for (int ti = ; scanf("%d%d", &n, &m) == && n && m; ti++) {
for (int i = ; i < n; i++) {
scanf("%d", a + i);
}
sort(a, a + n);
for (int i = ; i < m; i++) {
scanf("%d", b + i);
}
sort(b, b + m);
int ans = ;
for (int i = n - , j = m - ; i >= || j >= ;) {
if (i < ) {
ans += b[j--];
}
else if (j < ) {
ans += a[i--];
}
else {
if (a[i] == b[j]) {
ans += a[i];
i--; j--;
}
else if (a[i] > b[j]) {
ans += a[i--];
}
else {
ans += b[j--];
}
}
}
printf("%d\n", ans);
}
return ;
}
UVa LA 4636 Cubist Artwork 难度: 0的更多相关文章
- UVa LA 4094 WonderTeam 构造 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 11100 - The Trip, 2007 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVALive - 4636 Cubist Artwork(贪心)
题目链接 题意 给出正视图和侧视图,判断最少用几个立方体 分析 若存在高度相同的立方块,则以数目多的那面为准. #include <iostream> #include <cstdi ...
- UVA LA 7146 2014上海亚洲赛(贪心)
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...
- Uva LA 3902 - Network 树形DP 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- Uva 12124 Uva Live 3971 - Assemble 二分, 判断器, g++不用map.size() 难度:0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
随机推荐
- Vue 旅游网首页开发2 - 首页编写
Vue 旅游网首页开发2 - 首页编写 项目结构 首页开发 效果图 项目开发组件化 将页面的各个部分划分成不同的组件,有助于项目的开发和维护. 项目代码初始化 项目结构修改 1.删除整个 compin ...
- 标定版制作(棋盘、圆点、aruco等)
标定板这个东西,对于双目.立体视觉来说那都是必须的.我们这里提供一些做好的标定板,也提供制作标定板的制作方法 一.基本制作思路(以棋盘标定板为例) 1. “插入” - “表格” 根据提示选择多少行乘 ...
- ECS之Git服务器搭建
最简教程 ### . 安装Git 安装Git服务,命令如下: ```Shell $ yum install curl-devel expat-devel gettext-devel openssl-d ...
- CentOS下使用tcpdump网络抓包
tcpdump是Linux下的截获分析网络数据包的工具,对优化系统性能有很大参考价值. 安装 tcpdump不是默认安装的,在CentOS下安装: yum install tcpdump 在Ubunt ...
- Host 'xxx' is not allowed to connect to this MySQL server.
mysql开启远程连接 今天在服务器安装了mysql,准备用mysqlguitools远程登录的时候出错,提示:Host 'xxx' is not allowed to connect to this ...
- vue filters中使用data中数据
vue filters中 this指向的不是vue实例,但想要获取vue实例中data中的数据,可以采用下面方法.在 beforeCreate中将vue实例赋值给全局变量app0,然后filters中 ...
- xml转json和实体类的两种方式
本文为博主原创,未经允许不得转载: xml在http通信中具有较高的安全性和传输速度,所以应用比较广泛, 在项目中往往需要对xml,json和实体类进行相互转换,在这里总结一下自己所用到的一些方法: ...
- HDU 3567 Eight II(八数码 II)
HDU 3567 Eight II(八数码 II) /65536 K (Java/Others) Problem Description - 题目描述 Eight-puzzle, which is ...
- html 的 crossorigin 属性
添加这个属性, 并且服务器允许跨域后,会得到精确的报错信息. 添加这个属性,但服务器不允许跨域,就会被同源策略阻止加载资源. 不添加这个属性,只能知道报错,不知道具体信息. https://www.j ...
- [MySQL] timestamp和datetime的区别
建表语句如下: create table strong_passwd_whitelist( id int unsigned not null auto_increment, email_id int ...