zoukankan      html  css  js  c++  java
  • usaco Packing Rectangles

    太恶心了

    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<iostream>
    #include<sstream>
    #include<cmath>
    #include<climits>
    #include<string>
    #include<map>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<set>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    #define pb(a) push(a)
    #define INF 0x1f1f1f1f
    #define lson idx<<1,l,mid
    #define rson idx<<1|1,mid+1,r
    #define PI  3.1415926535898
    template<class T> T min(const T& a,const T& b,const T& c) {
        return min(min(a,b),min(a,c));
    }
    template<class T> T max(const T& a,const T& b,const T& c) {
        return max(max(a,b),max(a,c));
    }
    void debug() {
    #ifdef ONLINE_JUDGE
    #else
    
        freopen("d:\in1.txt","r",stdin);
        freopen("d:\out1.txt","w",stdout);
    #endif
    }
    int getch() {
        int ch;
        while((ch=getchar())!=EOF) {
            if(ch!=' '&&ch!='
    ')return ch;
        }
        return EOF;
    }
    struct situation
    {
        int h[4],w[4];
    }sit[500];
    struct answer
    {
        int h,w;
        answer(int h=0,int w=0):h(h),w(w){}
        bool operator < (const answer &ant) const
        {
            if(h*w!=ant.h*ant.w)
                return h*w<ant.h*ant.w;
            else return h<ant.h;
        }
        bool operator == (const answer &ant ) const
        {
            return h==ant.h&&w==ant.w;
        }
    }ans[2500];
    int h[4],w[4];
    void get()
    {
        int k=0;
        for(int st=0;st<(1<<4);st++)
        {
            int ord[4]={0,1,2,3};
            do
            {
                k++;
                for(int i=0;i<4;i++)
                {
                    if((1<<ord[i])&st)
                    {
                        sit[k].h[i]=w[ord[i]];
                        sit[k].w[i]=h[ord[i]];
                    }else
                    {
                        sit[k].h[i]=h[ord[i]];
                        sit[k].w[i]=w[ord[i]];
                    }
                }
            }while(next_permutation(ord,ord+4));
        }
    }
    
    int deal()
    {
        int h,w;
        int k=0;
        for(int i=1;i<=24*16;i++)
        {
            //1
            w=0,h=0;
            for(int j=0;j<4;j++)
            {
                h=max(h,sit[i].h[j]);
                w+=sit[i].w[j];
            }
            if(h>w)swap(h,w);
            ans[++k]=answer(h,w);
    
            //2
            w=0,h=0;
            for(int j=0;j<3;j++)
            {
                h=max(h,sit[i].h[j]);
                w+=sit[i].w[j];
            }
            h+=sit[i].h[3];
            w=max(w,sit[i].w[3]);
    
            if(h>w)swap(h,w);
            ans[++k]=answer(h,w);
    
            //3
            h=max(sit[i].h[0],sit[i].h[1])+sit[i].h[2]+sit[i].h[3];
            w=max(sit[i].w[0]+sit[i].w[1],sit[i].w[2],sit[i].w[3]);
            if(h>w)swap(h,w);
            ans[++k]=answer(h,w);
    
            //4
            h=max(sit[i].h[0],sit[i].h[1])+max(sit[i].h[2],sit[i].h[3]);
            w=max(sit[i].w[0]+sit[i].w[1],sit[i].w[2]+sit[i].w[3]);
    
            if(sit[i].w[0]+sit[i].w[1]>=sit[i].w[2]+sit[i].w[3])
            {
                if(sit[i].w[3]<=sit[i].w[0]&&sit[i].h[0]<=sit[i].h[1])
                    h=max(sit[i].h[0]+sit[i].h[3],sit[i].h[1]+sit[i].h[2]);
            }
            if(h>w)swap(h,w);
            ans[++k]=answer(h,w);
    
            //5
            h=sit[i].h[0];
            h+=max(sit[i].h[1],sit[i].h[2]+sit[i].h[3]);
            w=max(sit[i].w[0],sit[i].w[1]+max(sit[i].w[2],sit[i].w[3]));
            if(h>w)swap(h,w);
            ans[++k]=answer(h,w);
    
        }
        return k;
    }
    int main()
    {
        freopen("packrec.in","r",stdin);
        freopen("packrec.out","w",stdout);
        for(int i=0;i<4;i++)
            scanf("%d %d",&h[i],&w[i]);
        get();
        int k=deal();
        sort(ans+1,ans+k+1);
        k=unique(ans+1,ans+k+1)-ans;
        int res=ans[1].h*ans[1].w;
        printf("%d
    %d %d
    ",res,ans[1].h,ans[1].w);
        int i=2;
        while(ans[i].h*ans[i].w==res)
        {
            printf("%d %d
    ",ans[i].h,ans[i].w);
            i++;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    django xadmin后台集成DjangoUeditor
    vm虚拟机下的ubuntu16.04配置静态ip(NAT方式)
    关于mysql里的concat
    xml转换为数组格式
    关于json的中文转码问题
    判断是否是微信浏览器
    数组和xml的互相转换的封装函数
    关于微信登录的接口开发
    curl的封装类
    php里关于文件下载的方法(两种)
  • 原文地址:https://www.cnblogs.com/BMan/p/3554488.html
Copyright © 2011-2022 走看看