AK爷GhostCai的电脑又蓝屏了Orz

贪心题,确定一个maxh,限定h不大于一个值。枚举maxh。

check的时候的细节很多:

1.h>maxh但w<maxh交换的时候需要占用交换名额。

2.cnt<0了就应该return -1了。。。

突然忘记还有啥细节

代码如下

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N=1005;
int n,w[N],h[N],maxh,ans=0x3f3f3f3f;
bool cmp(int x,int y) {return x>y;}
int ck(int mxh) {
int tp=0,diff[N],cnt=n/2;
for(int i=1;i<=n;i++) {
if(h[i]>mxh&&w[i]>mxh) return -1;
if(h[i]>mxh&&w[i]<=mxh) diff[i]=-1,tp+=h[i],cnt--;
else if(w[i]>mxh) diff[i]=-1,tp+=w[i];
else diff[i]=w[i]-h[i],tp+=w[i];
}
if(cnt<0) return -1;
sort(diff+1,diff+1+n,cmp);
for(int i=1;i<=cnt;i++) {
if(diff[i]>0) tp-=diff[i];
else break;
}
return tp*mxh;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&h[i]),maxh=max(maxh,h[i]);
for(int i=1;i<=1000;i++) {
int t=ck(i);
if(t==-1) continue;
ans=min(ans,t);
}
cout<<ans;
}

[CodeForces]529B Group Photo 2的更多相关文章

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

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

  2. A1109. Group Photo

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

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

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

  4. 1109 Group Photo

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

  5. 1109 Group Photo (25 分)

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

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

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

  7. 1109. Group Photo (25)

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

  8. PAT 1109 Group Photo

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

  9. PAT_A1109#Group Photo

    Source: PAT A1109 Group Photo (25 分) Description: Formation is very important when taking a group ph ...

随机推荐

  1. iview datepicker 选择的时间少一天

    使用iview的datepicker时间选择器发现获取的value值是比实际要少一天,严格来说应该是时间格式不一样,datepicker获取的时间是UTC时间格式,也就是:yyyy-MM-ddTHH: ...

  2. 使用Ansible安装部署nginx+php+mysql之安装mysql(3)

    三.使用Ansible安装mysql 1.mysq.yaml文件 - hosts: clong remote_user: root gather_facts: no tasks: # 安装rpm包 - ...

  3. 关于IP数据包首部校验字段的理解

    关于IP数据包首部校验字段的理解 IP数据包格式及首部个字段:  www.2cto.com   对上表的各个数据项就不一一解释了,这里具体关注以下几个数据项: 1.4位首部长度:这里的长度指的是4By ...

  4. MyEclipse 2014 有用的几个快捷键

    ctrl+h  fileSearch ------------------------------------- MyEclipse 快捷键1(CTRL) ---------------------- ...

  5. TensorFlow 制作自己的TFRecord数据集

    官网的mnist和cifar10数据之后,笔者尝试着制作自己的数据集,并保存,读入,显示. TensorFlow可以支持cifar10的数据格式, 也提供了标准的TFRecord 格式,而关于 ten ...

  6. 服务器重启后启动Docker命令

    启动步骤: 1.启动Docker 守护进程 systemctl daemon-reload 2.Docker启动命令: systemctl start docker 3.查看docker服务是否启动 ...

  7. js严格模式下判断数据类型

    function isType(type) { return function (content) { let t = Object.prototype.toString.call(content). ...

  8. nmon和nmon analyser的下载和使用

    nmon 工具可以为 AIX 和 Linux 性能专家提供监视和分析性能数据的功能,AIX是IBM的一个操作系统,相比于Linux,使用范围不算很广,因此我们重点讲下Linux下的nmon应 用.首先 ...

  9. js sort根据数值大小自动排序(转)

    var arrDemo = new Array(); arrDemo[0] = 10; arrDemo[1] = 50; arrDemo[2] = 51; arrDemo[3] = 100; arrD ...

  10. Ajax发送简单请求案例

    所谓简单请求,是指不包含任何参数的请求.这种请求通常用于自动刷新的应用,例如证券交易所的实时信息发送.这种请求通常用于公告性质的响应,公告性质的响应无需客户端的任何请求参数,而是由服务器根据业务数据自 ...