题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2637

题意

积木,有左视图和前视图,问最少几块积木

思路

明显,把前视图视作列,左视图视作行,从大到小排列行和列,如果此时未处理的行列最大值恰巧相等为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的更多相关文章

  1. UVa LA 4094 WonderTeam 构造 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. UVa 11100 - The Trip, 2007 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. UVALive - 4636 Cubist Artwork(贪心)

    题目链接 题意 给出正视图和侧视图,判断最少用几个立方体 分析 若存在高度相同的立方块,则以数目多的那面为准. #include <iostream> #include <cstdi ...

  4. UVA LA 7146 2014上海亚洲赛(贪心)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...

  5. Uva LA 3902 - Network 树形DP 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  6. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. 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 ...

随机推荐

  1. iOS进阶之使用 NSURLProtocol 拦截 HTTP 请求(转载)

    这篇文章会提供一种在 Cocoa 层拦截所有 HTTP 请求的方法,其实标题已经说明了拦截 HTTP 请求需要的了解的就是 NSURLProtocol. 由于文章的内容较长,会分成两部分,这篇文章介绍 ...

  2. UI自动化(十四)yaml配置文件

    import yamlimport jsonf = open('config.yaml','rb')data = yaml.load(f)print(json.dumps(data,indent=4) ...

  3. Java中的抽象

    什么是抽象类? 如果一个类没有足够的信息去描述一个具体的对象,那么这样的类我们就称它为抽象类.这很好理解,就如同动物是一个很广泛的概念,由于在动物这个类里,我们无法用很详细的信息去描述狗狗这个具体的对 ...

  4. bzoj1997 [HNOI2010]平面图判定Plana

    bzoj1997 [HNOI2010]平面图判定Planar 链接 bzoj luogu 思路 好像有很多种方法过去.我只说2-sat 环上的边,要不在里面,要不在外边. 有的边是不能同时在里面的,可 ...

  5. USACO比赛题泛刷

    随时可能弃坑. 因为不知道最近要刷啥所以就决定刷下usaco. 优先级排在学习新算法和打比赛之后. 仅有一句话题解.难一点的可能有代码. 优先级是Gold>Silver.Platinum刷不动. ...

  6. C# 简单粗暴写日志

    public static void WriteLog(string text) { string path = AppDomain.CurrentDomain.BaseDirectory; path ...

  7. 论文笔记:Deeper and Wider Siamese Networks for Real-Time Visual Tracking

    Deeper and Wider Siamese Networks for Real-Time Visual TrackingUpdated on 2019-04-01 16:10:37 Paper ...

  8. 【HNOI 2017】影魔

    Problem Description 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还 ...

  9. mybatis-ehcache整合中出现的异常 ibatis处理器异常(executor.ExecutorException)解决方法

    今天学习mabatis时出现了,ibatis处理器处理器异常,显示原因是Executor was closed.则很有可能是ibatis的session被关闭了, 后面看了一下测试程序其实是把sqlS ...

  10. 剑指offer 06:旋转数组的最小数字

    题目描述把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...