题目大意:

有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. qml package 的使用

    什么时候使用这个.就是多个view使用同一个deleagte的时候. The Package class is used in conjunction with VisualDataModel to ...

  2. windows常见已知熟悉操作命令

    WIN+R--->输入CMD---->回车有关某个命令的详细信息,请键入 HELP 命令名ASSOC          显示或修改文件扩展名关联.ATTRIB         显示或更改文 ...

  3. Rsync+sersync文件实时同步

    一.为什么要用Rsync+sersync架构1.sersync是基于Inotify开发的,类似于Inotify-tools的工具2.sersync可以记录下被监听目录中发生变化的(包括增加.删除.修改 ...

  4. 为什么要进行傅立叶变换?傅立叶变换究竟有何意义?如何用Matlab实现快速傅立叶变换

    写在最前面:本文是我阅读了多篇相关文章后对它们进行分析重组整合而得,绝大部分内容非我所原创.在此向多位原创作者致敬!!!一.傅立叶变换的由来关于傅立叶变换,无论是书本还是在网上可以很容易找到关于傅立叶 ...

  5. 纯JS文本在线HTML编辑器KindEditor

    KindEditor(http://www.kindsoft.net)是一款比较专业,主流,好用的在线HTML编辑器. 它除了可以将文本进行编辑.将Word中的内容复制进来外,本身还可以拖动缩放(右下 ...

  6. Repeater控件的分页效果

    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign=" ...

  7. 微软.NET Framework 4.5.2 RTM正式版

    今天,微软.NET开发团队发布.NET Framework 4.5.2 RTM正式版.新版框架继续高度兼容现有的.NET Framework 4.4.5.4.5.1等版本,该版本框架与旧版的.NET ...

  8. 生成1~n的全排列

    输入正整数n,输出n的全排列. 样例输入1: 3 样例输出1: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 分析: 按字典序从小到大的顺序输出所有的排列. (字典序:两个序 ...

  9. hdu 1950 最长上升子序列

    //Accepted 3540 KB 62 ms //dp 最长上升子序列 #include <cstdio> #include <cstring> #include < ...

  10. VM虚拟机中Ubuntu无法连接网络

    之前Ubuntu是可以上网的,但是今天打开后发现上不了网了,经过一番折腾,弄好了,记录下. 方案一:将网络连接设置为自定义NAT VM ->设置-> 硬件->网络适配器 这么已修改就 ...