码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 1445 Cubist Artwork

时间:2015-07-17 21:03:04      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

题目大意:给出一个不规则图形的正视图和左视图,问说最少使用多少个小立方体。

解题思路:很容易想到,如果正视图和左视图有一列刚好高度相等,则可省去一列。

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int w, d;
    while (scanf("%d%d", &w, &d) && w + d) {
        int h, F[25] = {0}, S[25] = {0};
        for (int i = 0; i < w; i++) {
            scanf("%d", &h);
            F[h]++;
        }
        for (int i = 0; i < d; i++) {
            scanf("%d", &h);
            S[h]++;
        }

        int ans = 0;
        for (int i = 1; i <= 20; i++)
            ans += max(F[i], S[i]) * i;

        printf("%d\n", ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

UVA - 1445 Cubist Artwork

标签:

原文地址:http://blog.csdn.net/kl28978113/article/details/46932123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!