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 ...
随机推荐
- CORS:source,princple,implimentation in Spring
CORS = Cross-Origin Resource Sharing 一种跨域访问技术 什么是 Origin 要理解CORS,首先得理解什么是 “Origin”.参见RFC645 ...
- WPF DataGrid 绑定行双击行命令
WPF DataGrid 绑定行双击行命令 <DataGrid ...> <DataGrid.InputBindings> <MouseBinding MouseActi ...
- HDU 2665 Kth number(主席树静态区间第K大)题解
题意:问你区间第k大是谁 思路:主席树就是可持久化线段树,他是由多个历史版本的权值线段树(不是普通线段树)组成的. 具体可以看q学姐的B站视频 代码: #include<cmath> #i ...
- nDPI-dev分析
目前在 分为两个层次:其一是应用分析,学会如何使用:其二是原理分析,看懂它如何实现. 1. 打包该数据帧,搜集l3.l4层报头信息 2. 查询链接跟踪(如果已被标识,则直接获取到该数据帧所属协议类型) ...
- Docker跨主机网络联通之etcd实现
搭建ETCD集群 查看NODE1机器IP,并启动ETCD ubuntu@docker-node1:~$ ifconfig eth0 eth0: flags=4163<UP,BROADCAST,R ...
- UE4外包团队:更新一下UE4和Unity3D案例
全部的贴图都是用出的法线贴图构建的话只用了阳光和天光,都是静态光源,视角是第一人称模板最后的效果嘛就是全4K,120帧,0错误0警告,场景小是小了点但是效果还不错. 工作活有时间更新,欢迎有UE4和U ...
- Python绘制温度变化曲线
导入必要的第三方库 from requests import get import matplotlib.pyplot as plt /usr/lib/python3/dist-packages/ma ...
- OpenGL.教程
5.第五课:带纹理的立方体.html(http://www.opengl-tutorial.org/cn/beginners-tutorials/tutorial-5-a-textured-cube/ ...
- 关于两栏布局,三栏布局,一级点击三角触发select的onchange事件问题
首先看这样一个效果:,这个截图来自移动端的列表的一整行,在这个效果当中,存在两个技术点,首先选择祝福卡这个宽度是一定的,右边的部分,宽度随着手机屏幕的宽度而自适应,再一个技术点就是点击最右侧向下箭头, ...
- sqlite3如何判断一个表是否已经存在于数据库中 C++
SELECT count(*) AS cnt FROM sqlite_master WHERE type='table' AND name='table_name';cnt will return 0 ...