Codeforce_827C_Two Seals_Educational Codeforces Round 26

32 篇文章 0 订阅
9 篇文章 0 订阅

C. Two Seals
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
One very important person has a piece of paper in the form of a rectangle a × b.

Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).

A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).

Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

Examples
input
2 2 2
1 2
2 1
output
4
input
4 10 9
2 3
1 1
5 10
9 11
output
56
input
3 10 10
6 6
7 7
20 5
output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.

In the second example you can’t choose the last seal because it doesn’t fit. By choosing the first and the third seals you occupy the largest area.

In the third example there is no such pair of seals that they both can fit on a piece of paper.
贪心,脑洞,
我的处理把所有的矩阵,都初始化这样


| |
| |


然后就只有5种情况
这里写图片描述

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    int x,y;
}num[99999];
bool cmp(node a,node b)
{
    return a.y<b.y;
}
int main()
{
   int n,s_x,s_y;
   while(cin>>n>>s_x>>s_y)
   {
       int ttx=s_x,tty=s_y;
       s_x=min(ttx,tty);
       s_y=max(ttx,tty);
       int i,j,tx,ty;
       for(i=0;i<n;i++)
       {
        scanf("%d%d",&tx,&ty);
        num[i].x=min(tx,ty);
        num[i].y=max(tx,ty);
       }
       sort(num,num+n,cmp);
       int ans=0;
        int mm=0;
        tx=ty=0;
       for(i=n-1;i>0;i--)
       {
           if(num[i].x<=s_x&&num[i].y<=s_y)
           {
               ans=num[i].x*num[i].y;
               tx=s_x-num[i].x;
               ty=s_y;
           }
           else continue;
           for(j=i-1;j>=0;j--)
           {
               if(num[j].x<=tx&&num[j].y<=ty)
               {
                    mm=max( ans+num[j].x*num[j].y,mm);
               }
               else if(num[i].y+num[j].x<=s_y&&max(num[i].x,num[j].y)<=s_x)
               {
                   mm=max( ans+num[j].x*num[j].y,mm);
               }
               else if(num[i].y+num[j].y<=s_y&&max(num[i].x,num[j].x)<=s_x)
               {
                   mm=max( ans+num[j].x*num[j].y,mm);
               }
               else if(num[i].x+num[j].y<=s_x&&max(num[i].y,num[j].x)<=s_y)
               {
                   mm=max( ans+num[j].x*num[j].y,mm);
               }
               else if(num[i].x+num[j].x<=s_y&&max(num[i].y,num[j].y)<=s_x)
                 mm=max( ans+num[j].x*num[j].y,mm);
           }

       }
       cout<<mm<<endl;
   }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值