题目大意:

有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. WPF TreeView的使用

    WPF提供了treeView控件,利用该控件开发者可以将数据分层显示在树结构中.当然其中需要用到Binding的机制,有用的类包括:ObjectDataProvider.DataTemplate.Hi ...

  2. 判断子元素(or属性)是否存在

    if(typeof($("#aid").attr("rel"))=="undefined") 即可

  3. js基础之COOKIE

    一.COOKIE的封装函数 function setCookie(name,value,eDate){ var oDate = new Date(); oDate.setDate(oDate.getD ...

  4. MyEclipse 修改代码不生效

    最近得了一个项目,java开发的web项目,修改代码时,无论怎么改,都不生效: 各种度娘,没用. 原因是没有建立发布设定 这个东西我开始不理解它的作用,现在知道了: mysqleclipse项目在一个 ...

  5. mongo .update

    db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...

  6. xcode开发的6个小技巧

    Xcode是iPhone和iPad开发者用来编码或者开发iOS app的IDE.Xcode有很多小巧但很有用的功能,很多时候我们可能没有注意到它们,也或者我们没有在合适的水平使用这些功能简化我们的iO ...

  7. 使用sslsplit嗅探tls/ssl连接

    首先发一个从youtube弄到的sslsplit的使用教程 http://v.qq.com/page/x/k/s/x019634j4ks.html 我最近演示了如何使用mitmproxty执行中间人攻 ...

  8. C# 展开和折叠代码的快捷键(总结)

    C# 展开和折叠代码的快捷键 VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M +  ...

  9. 知道创宇研发技能表v2.2

    知道创宇研发技能表v2.2 2014/3/9 发布 by @知道创宇(www.knownsec.com) @余弦 & 行之 知道创宇是国内Geek十足且普遍被认为特别有前途的互联网安全公司, ...

  10. oracle 10gwindow7安装添加内容

    F:\软件\database\stage\prereq\db\refhost.xml <!--Microsoft Windows 7 .Windows 8--> <OPERATING ...