UVA1445-Cubist artwork.

Source: Internet
Author: User

Question Link


Question: Use a number of other large cubes to build blocks. Each cube can be directly placed on a grid on the ground, or placed on another cube to provide a positive view and a lateral view, find the minimum number of cubes to build.

Idea: to build a cube with the least amount, it means that the height wh of each vertical cube seen on the front is best utilized by the height DH seen on the side. Therefore, we use the front as the benchmark. The total number of cubes required by the front plus the number of cubes required by the DH on the side cannot use the front Wh, which is the minimum number of cubes required.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 100;int a[MAXN], b[MAXN], num1[MAXN], num2[MAXN];int main() {    int w, d;    while (scanf("%d%d", &w, &d) && w && d) {        memset(num1, 0, sizeof(num1));        memset(num2, 0, sizeof(num2));        for (int i = 1; i <= w; i++) {            scanf("%d", &a[i]);             num1[a[i]]++;        }        for (int i = 1; i <= d; i++) {            scanf("%d", &b[i]);             num2[b[i]]++;        }        int sum = 0;        for (int i = 1; i <= MAXN; i++)            sum += max(num1[i], num2[i]) * i;        printf("%d\n", sum);     }    return 0;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.