• 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake


    Description

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was equal to one.

    From a cooking book Dasha learned that a cake must have a form of a rectangular parallelepiped constructed from cake layers of the same sizes.

    Dasha decided to bake the biggest possible cake from the bought cake layers (possibly, using only some of them). It means that she wants the volume of the cake to be as big as possible. To reach this goal, Dasha can cut rectangular pieces out of the bought cake layers. She always cuts cake layers in such a way that cutting lines are parallel to the edges of that cake layer. Dasha isn't very good at geometry, so after cutting out a piece from the original cake layer, she throws away the remaining part of it. Also she can rotate a cake layer in the horizontal plane (swap its width and length).

    Dasha wants her cake to be constructed as a stack of cake layers of the same sizes. Each layer of the resulting cake should be made out of only one cake layer (the original one or cut out from the original cake layer).

    Help Dasha to calculate the maximum possible volume of the cake she can bake using given cake layers.

    Input

    The first line contains an integer n(1 ≤ n ≤ 4000) — the number of cake layers that Dasha can use.

    Each of the following n lines contains two integer numbers ai and bi(1 ≤ ai, bi ≤ 106) — the length and the width of i-th cake layer respectively.

    Output

    The first line of the output should contain the maximum volume of cake that can be baked using given layers.

    The second line of the output should contain the length and the width of the resulting cake. If there are many solutions with maximum possible volume, print any of them.

    Sample Input

    Input
    5
    5 12
    1 1
    4 6
    6 4
    4 6
    Output
    96
    6 4
    Input
    2
    100001 900000
    900001 100000
    Output
    180000000000
    900000 100000

    Hint

    In the first example Dasha doesn't use the second cake layer. She cuts 4 × 6 rectangle from the first cake layer and she uses other cake layers as is.

    In the second example Dasha cuts off slightly from the both cake layers.

    题意:给你n个高度为1的蛋糕,分别有长和宽; 让你将这些蛋糕垒起来平行于边切,使得每块蛋糕长宽相同;求最大体积,输出体积和长、宽;

    思路:输入时统一长和宽(宽小于长),然后按照宽从小到大排序,两重循环,i=0~n-1,j=0~n-1,计数vec[0~j].second>=ves[i].second有多少,

    记为num,mp[i][j]=num,由此可以看出mp[i][j]表示,以ves[i].second为宽,以ves[j].first为长的蛋糕层的个数,那么以ves[i].second为宽,以ves[j].first为长的蛋糕的体积最大为;ves[i].second*ves[j].first*mp[i][j];最后两层循环遍历,计算以每个mp[i][j]为蛋糕大小的体积,找出最大值;

    代码如下:

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    using namespace std;
    const int maxn=4050;
    typedef long long LL;
    int mp[maxn][maxn];
    int main()
    {
        int n;
        LL x,y;
        while(cin>>n)
        {
            memset(mp, 0, sizeof(mp));
            vector< pair<LL ,LL> >vec;
            for(int i=0; i<n; i++)
            {
                cin>>x>>y;
                if(x>y) swap(x, y);
                vec.push_back(make_pair(x, y));
            }
            sort(vec.begin(), vec.end());
            for(int i=n-1; i>=0; i--)
            {
                int num=0;
                for(int j=n-1;j>=0;j--)
                {
                    if(vec[j].second>=vec[i].second)
                        num++;
                    mp[i][j]=num;
                }
            }
            LL ans=0,ansx=0,ansy=0;
            for(int i=0; i<n; i++)
            {
                for(int j=0; j<n; j++)
                {
                    LL x=vec[i].first;
                    LL y =vec[j].second;
                    LL sum=x*y;
                    LL tot=sum*mp[j][i];
                    if(ans < tot)
                    {
                        ans=tot;
                        ansx=x;
                        ansy=y;
                    }
                }
            }
            cout<<ans<<endl;
            cout<<ansx<<" "<<ansy<<endl;
        }
        return 0;
    }


     

  • 相关阅读:
    使用 yo 命令行向导给 SAP UI5 应用添加一个新的视图
    SAP Fiori Elements 应用的 manifest.json 文件运行时如何被解析的
    SAP UI5 标准应用的多语言支持
    微软 Excel 365 里如何设置下拉菜单和自动高亮成指定颜色
    SAP Fiori Elements 应用里的 Title 显示的内容是从哪里来的
    本地开发好的 SAP Fiori Elements 应用,如何部署到 ABAP 服务器上?
    如何在 Cypress 测试代码中屏蔽(Suppress)来自应用代码报出的错误消息
    教你一招:让集群慢节点无处可藏
    应用架构步入“无服务器”时代 Serverless技术迎来新发展
    MySQL数据库事务隔离性的实现
  • 原文地址:https://www.cnblogs.com/chen9510/p/5517712.html
Copyright © 2020-2023  润新知