zoukankan      html  css  js  c++  java
  • CodeForces

    题目链接:https://vjudge.net/contest/242578#problem/B

    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.

    Examples
    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
    Note

    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,代表蛋糕有n层,接下来n行代表每层蛋糕的长度宽度,每层蛋糕的高度都是1 ,长宽可以交换位置,问你长宽取值为多少时,切得的蛋糕体积最大

    个人思路:由题可知,长宽的取值一定在已有的长宽中得到,这题其实就是暴力,枚举每一个长和每一个宽,取最大的那个就是答案了

    看代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<stdio.h>
    #include<string.h>
    #include<cmath>
    #include<math.h>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<map>
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const int maxn=4e3+10;
    const int maxk=100+10;
    const int maxx=1e4+10;
    const ll maxe=1000+10;
    #define INF 0x3f3f3f3f3f3f
    struct cake
    {
        int w,l;
    }a[maxn];
    bool cmp(const cake a,const cake b)
    {
        return a.w<b.w;
    }
    int main()
    {
        ll n,ans=0,answ,ansl;
        int c[maxn];
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i].w>>a[i].l;
            if(a[i].w>a[i].l)
                swap(a[i].w,a[i].l);
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++)
        {
            int sum=0;
            for(int j=0;j<n;j++)
            {
                if(a[j].l>=a[i].l)
                {
                    c[sum++]=a[j].w;
                }
            }
            for(int j=0;j<sum;j++)
            {
                ll res;
                res=(ll)a[i].l*c[j]*(sum-j);
                if(res>ans)
                {
                    ans=res;
                    answ=c[j];
                    ansl=a[i].l;
                }
            }
        }
        cout<<ans<<endl;
        cout<<answ<<" "<<ansl<<endl;
        return 0;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
    简单的使用SLF4J门面和log4j
    详细的Log4j使用教程
    java的Mybatis动态代理方式(二)
    java的一个基础的Mybatis例子(一)
    java的注解学习
    ArrayList输出的几种方法
    自己写的一个java链接数据库的类
    ipv4的TCP的几个状态 (SYN, FIN, ACK, PSH, RST, URG)
    tomcat的CATALINA_HOME环境变量可以不用设置
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9400392.html
Copyright © 2011-2022 走看看