题目大意:

有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. 使用MediaPlayer播放音频-----之二

    MediaPlayer播放不同来源的音频文件: 一.播放应用的资源文件 1.调用MediaPlayer的create(Context  context , int  resid)方法加载指定资源文件. ...

  2. ajax实际的应用

    假设两个选择框,前面一个是省份,后面一个是地级市.当选择某一省份的时候,后面的选择框会有此省份对应的地级市.可以根据ajax来实现. function load{ if(true){      var ...

  3. 标签视图控制器UITabBarController

    标签视图控制器 UITabBarController FirstViewController*first = [[FirstViewController alloc] init]; //创建一个UIT ...

  4. POJ 1011 Sticks dfs,剪枝 难度:2

    http://poj.org/problem?id=1011 要把所给的集合分成几个集合,每个集合相加之和ans相等,且ans最小,因为这个和ans只在[1,64*50]内,所以可以用dfs一试 首先 ...

  5. JobTracker启动流程源码级分析

    org.apache.hadoop.mapred.JobTracker类是个独立的进程,有自己的main函数.JobTracker是在网络环境中提交及运行MR任务的核心位置. main方法主要代码有两 ...

  6. 虚拟机的apache服务器不能被主机访问的问题

    我在centos虚拟机上安装了elasticsearch服务,虚拟机里测试正常,但主机却无法访问elasticsearch.要说的是,虚拟机采用桥接模式,与主机相互ping得通. 后来查了资料发现,这 ...

  7. Ubuntu14.04安装和配置ROS Indigo(一)

    安装ROS 配置Ubuntu的软件源 配置Ubuntu要求允许接受restricted.universe和multiverse的软件源,可以根据下面的链接配置: https://help.ubuntu ...

  8. WEKA使用教程(界面工具的用法)

    WEKA使用教程 目录 1. 简介2. 数据格式3.数据准备4. 关联规则(购物篮分析)5. 分类与回归6. 聚类分析 1. 简介 WEKA的全名是怀卡托智能分析环境(Waikato Environm ...

  9. Quartz之主方法运行

    import static org.quartz.JobBuilder.newJob; import static org.quartz.TriggerBuilder.newTrigger; impo ...

  10. 推荐一款作图神器:ProcessOn

    本人近日发现一款作图神器:ProcessOn 它是一款在线的作图工具,完全国产,前台是用HTML5  Canvas加javascript做绘图,后台用java实现数据处理和图片生成, 整站UI基本类似 ...