题目大意:

有n个矩形在地上排成一列,不可重叠,已知他们的宽度w和高度h,现在使至多[n / 2]个矩形旋转90度,问最后可以用多小的矩形恰好覆盖这n个矩形,求满足条件的最小矩形面积。

n, w, h <= 1000。

分析:

数据范围比较小,可以枚举答案矩形的高度H,判断是否能只旋转至多[n / 2]个矩形使得n个矩形的高度均不超过H,再用剩下的操作次数尽量使得总宽度变少。

贪心旋转,尽量把w比h大很多的矩形旋转,所以可以对矩形按照{w - h}排序,贪心旋转即可。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#define maxn 1001
#define INF ~0u >> 1
using namespace std;
struct Node
{
int w,h;
bool operator <(const Node &ths) const
{
return w-h>ths.w-ths.h;
}
};
Node a[maxn],b[maxn];
int main()
{
int n,ans=INF;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&a[i].w,&a[i].h);
for(int i=1;i<maxn;i++)
{
memcpy(b,a,sizeof(a));
int flag=0,sum=0;
for(int j=0;j<n;j++)
{
if(b[j].h>i)
{
if(b[j].w>i)
{
flag=1;
break;
}
else
{
swap(b[j].w,b[j].h);
sum++;
}
}
}
if(flag||sum*2>n)
continue;
sort(b,b+n);
for(int j=0;j<n&&(sum+1)*2<=n;j++)
{
if(b[j].w<=i&&b[j].h<b[j].w)
{
swap(b[j].h,b[j].w);
sum++;
}
}
int ww=0;
for(int j=0;j<n;j++)
ww+=b[j].w;
//printf("%d %d\n",ww,i);
ans=min(ans,ww*i);
}
printf("%d\n",ans);
return 0;
}

codeforce Group Photo 2 (online mirror version)的更多相关文章

  1. CF529B 【Group Photo 2 (online mirror version)】

    贪心枚举最后方案中最大的h,设为maxh若某个人i的wi与hi均大于maxh,则此方案不可行若某个人恰有一个属性大于maxh,则可确定他是否换属性剩下的人按wi-hi从大到小排序后贪心选择O(nlog ...

  2. CF 529B Group Photo 2 (online mirror version)

    传送门 解题思路 这道题要用到贪心的思路,首先要枚举一个h的最大值,之后check.如果这个东西的w[i]与h[i]都大于枚举的值就直接return false,如果w[i]比这个值小,h[i]比这个 ...

  3. A1109. Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  4. PAT A1109 Group Photo (25 分)——排序

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  5. 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  6. 1109 Group Photo (25 分)

    1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...

  7. PAT 1109 Group Photo[仿真][难]

    1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of for ...

  8. 1109. Group Photo (25)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  9. PAT 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

随机推荐

  1. Redis persistence demystified - part 2

    重写AOF 当AOF文件太大时,Redis将在临时文件重新写入新的内容.重写不会读取旧的AOF文件,而是直接访问内存中数据,以便让新产生的AOF文件最小,重写过程不需要读取磁盘. 重写完成后,Redi ...

  2. hdu 4622 Reincarnation

    http://acm.hdu.edu.cn/showproblem.php?pid=4622 用字典树把每一个字符串对应成一个整数 相同的字符串对应到相同的整数上 把所用的串对应的整数放在一个数组里 ...

  3. POJ 3264 Balanced Lineup 线段树 第三题

    Balanced Lineup Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line ...

  4. Problem C 链表

    Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报 ...

  5. matlab 画框(二) 去白边

    在matlab图像处理中,为了标识出图像的目标区域来,需要利用plot函数或者rectangle函数,这样标识目标后,就保存图像. 一般saves保存的图像存在白边,可以采用imwrite对图像进行保 ...

  6. 传Windows 9预览版今秋发布

    据ZDNet长期关注微软动态的资深人士玛丽•乔•弗利(Mary Jo Foley)称,Windows 9预览版将会在9月或者10月推出.按照这一进度,代号为“Threshold’”的Windows 9 ...

  7. JVM-运行时数据区

                                                                              运行时数据区示意图                 ...

  8. 国内android帮助文档镜像网站---http://wear.techbrood.com/develop/index.html

    http://wear.techbrood.com/develop/index.html

  9. 设置navigation baritem方法

    UIButton *RightBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; [RightBtn setImage:[UIImage im ...

  10. mp3文件 ID3v2 帧标识的含义

    mp3文件 ID3v2 帧标识的含义 Declared ID3v2 frames The following frames are declared in this draft. 4.20 AENC ...