Two Seals codeforces 837c

Two Seals

 

一个矩形a*b,若干子矩形,子矩形中选2个,不重叠能覆盖最大

 

思路:

  枚举;

 

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 105
int n,xi,yi,ai[maxn],bi[maxn],ans;
inline void in(int &now)
{
    char Cget=getchar();now=0;
    while(Cget>'9'||Cget<'0') Cget=getchar();
    while(Cget>='0'&&Cget<='9')
    {
        now=now*10+Cget-'0';
        Cget=getchar();
    }
}
int main()
{
    in(n),in(xi),in(yi);
    for(int i=1;i<=n;i++) in(ai[i]),in(bi[i]);
    for(int i=1;i<=n;i++)
    {
        int a=xi-ai[i],b=yi-bi[i];
        if(a>=0&&b>=0) for(int v=i+1;v<=n;v++)
        {
            if(ai[v]<=a&&bi[v]<=yi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(ai[v]<=b&&bi[v]<=xi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(bi[v]<=a&&ai[v]<=yi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(bi[v]<=b&&ai[v]<=xi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
        }
        a=xi-bi[i],b=yi-ai[i];
        if(a>=0&&b>=0)for(int v=i+1;v<=n;v++)
        {
            if(ai[v]<=a&&bi[v]<=yi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(ai[v]<=b&&bi[v]<=xi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(bi[v]<=a&&ai[v]<=yi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
            if(bi[v]<=b&&ai[v]<=xi) ans=max(ai[i]*bi[i]+ai[v]*bi[v],ans);
        }
    }
    cout<<ans;
    return 0;
}

 

posted @ 2017-08-09 11:13  IIIIIIIIIU  阅读(295)  评论(0编辑  收藏  举报