zoukankan      html  css  js  c++  java
  • noip模拟赛 隔壁

    分析:体积最大的比较好处理,对于第(i,j)格的高度取min(a[i],b[j])就好了,保证让每个格子的高度最大.对于最小的情况,只要让第i列上有一个格子高度为a[i],其它全是0,第j行有一个高度为b[j],其它全是0就好了.如果a,b中有相同的元素,那么它们可以共用一个格子,因为最后每个高度都要取到,还要减去共用格子的高度,所以答案为Σa[i] + Σb[j] - Σ共用格子的高度*个数.

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int n, m, sum, a[1010], b[1010], ans, cnt, tot[1010];
    int main()
    {
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &a[i]);
            sum += a[i];
        }
        for (int i = 1; i <= m; i++)
        {
            scanf("%d", &b[i]);
            sum += b[i];
        }
        sort(a + 1, a + 1 + n); 
        sort(b + 1, b + 1 + m); 
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                ans += min(a[i], b[j]);
        for (int i = 1; i <= n; i++)
            tot[a[i]]++;
        cnt = unique(a + 1, a + 1 + n) - a - 1;
        for (int i = 1; i <= cnt; i++)
        {
            int tott = 0;
            for (int j = 1; j <= m; j++)
                if (b[j] == a[i])
                    tott++;
            sum -= min(tott, tot[a[i]]) * a[i];
        }
        printf("%d %d
    ", sum, ans);
    
        return 0;
    }
  • 相关阅读:
    前端好用js库
    springmvc 配置之 mvc:default-servlet-handler
    springmvc配置之mvc:annotation-driven
    spring mvc 配置之 context:annotation-config vs component-scan
    React 学习笔记
    数据结构乱写
    字符串乱写
    HEOI2020 游记
    奇怪的基础容斥数学课件
    省选模拟104 题解
  • 原文地址:https://www.cnblogs.com/zbtrs/p/7722014.html
Copyright © 2011-2022 走看看