题目

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. Unity入门一,什么是GameObject,MonoBehaviour

    Unity入门一,什么是GameObject,MonoBehaviour GameObject和Component Unity是一个Component-Based的引擎,所有物体都是GameObjec ...

  2. vue - 列表显示(列互相影响,全选控制,更新数据)

    要实现的效果为:全选,且列A列B互相影响,列B勾选则列A一定勾选,列A取消勾选,则相应列B取消勾选 数组 vue中列表渲染有些不是相应式的 var list=[ { a:'aaaa', b:'ddd' ...

  3. Parallels Desktop 14.1.3中文版win系统安装教程

    parallels desktop 14 中文版(pd虚拟机)是mac上最强大也是最好用的虚拟机软件,本站第一时间为大家带来这款parallels desktop 14 破解版,最新版本的parall ...

  4. UITextField只能输入数字NSCharacterSet实现

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...

  5. centos7安装supervisor

    安装supervisor cd /root/tools/ wget http://pnxcvm0bq.bkt.clouddn.com/get-pip.py python get-pip.py pip ...

  6. 2018年-2019年第二学期第五周C#学习个人总结

    在本周我学习了第五章面向对象高级中的5.3多态,5.3多态中主要包括重写父类方法,多态的实现,base关键字,里氏转换原则,Object类.在重写父类方法中要求当重写父类的方法时,要求子类的方法名,参 ...

  7. python 之生成器的介绍

    # 用生成器(generators)方便地写惰性运算 def double_numbers(iterable): for i in iterable: yield i + i # 生成器只有在需要时才 ...

  8. eclipse报错:Multiple annotations found at this line: - String cannot be resolved to a type解决方法实测

    Multiple annotations found at this line:- String cannot be resolved to a type- The method getContext ...

  9. Git初识学习

    初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 使用命令git add <file>,注意,可反复多次使用,添加多个文件: 使用命令git commit ...

  10. react的this.setState没有触发render

    一.浅比较 出现情况: 明明改变了值, 并且回调函数也触发了, 但是就是不触发render import React, { PureComponent } from 'react' import { ...