题目

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. Vagrant Box下载缓慢解决方法

    box 搜索页面:https://atlas.hashicorp.com/boxes/search example:homestead 1,选中box和版本,先根据提示安装 2,获取box下载地址,采 ...

  2. 利用phpspider爬取网站数据

    本文实例原址:PHPspider爬虫10分钟快速教程 在我们的工作中可能会涉及到要到其它网站去进行数据爬取的情况,我们这里使用phpspider这个插件来进行功能实现. 1.首先,我们需要php环境, ...

  3. Linux查看当前目录下文件名中包含指定字符的文件

    find . -type f -name "edaijia* 结果:

  4. httplib和urllib2常用方法

    都是几年前用过的,现在翻出来记录一下. import httplib import urllib2 import socket ##---------------------------------- ...

  5. Vue/Egg大型项目开发(一)搭建项目

    项目Github地址:前端(https://github.com/14glwu/stuer)后端(https://github.com/14glwu/stuer-server) 项目线上预览:http ...

  6. Client not ready yet.....

    提示Client not ready yet.....程序安装上就提示停止了 Logcat无提示 只有run里边提示  Client not ready yet....... 我尝试了  Clean ...

  7. Caffe+CUDA8.0+CuDNNv5.1+OpenCV3.1+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe + CUDA8.0 + CuDNNv5.1 + OpenCV3.1 + Ubuntu14.04  配置参考文献 ---- Wang Xiao  Anhui University  CVPR ...

  8. scala链接mysql

    方法一:链接并操作mysql //链接Mysqlval driver = "com.mysql.jdbc.Driver"val url = "jdbc:mysql://1 ...

  9. 9、Docker私有registry

    Docker Registry分类 Docker 默认是使用https的,但是如果在自己得私有局域网中,你指明使用http也是可以的. Registry主要的作用是托管镜像: 运行docker reg ...

  10. C语言学习——bsmap-2.74_main.cpp

    素材路径:https://www.codeforge.cn/read/428275/bsmap-2.74-_-main.cpp__html 1.C/C++预处理指令,常见的预处理指令如下: #空指令, ...