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. webpack学习笔记(4)--webpack.config.js

    devtool参数 这个参数控制是否生成,以及如何生成source map,已经在官网的doc说明总结了. 下表总结了各个参数和使用的情况 devtool 构建速度 重新构建速度 生产环境 品质(qu ...

  2. nmon分析文件各sheet含义

    sheet名称sheet含义 SYS_SUMM系统汇总,蓝线为cpu占有率变化情况,粉线为磁盘IO的变化情况: AAA关于操作系统以及nmon本身的一些信息: BBBB系统外挂存储容量以及存储类型: ...

  3. asp.net mvc--传值-前台->后台

    前端传值->后端 一.Model Binding 方式 前台 @model ADMgr.Web.Models.ListModel 后台 [HttpPost] public ActionResul ...

  4. 使用joomla通过CSV文件上传数据存入数据库并使用JavaScript验证码是否符合规则

    1,实现效果截图 2,A.php上传CSV文件表单 2-1:html结构使用jqeury.form.min.js表单框架异步提交 <div class="uploadFile bord ...

  5. Web安全扫描工具

    使用 Ibm security appscan  进行WEB安全扫描. 1.SQL注入: 2.发现内部IP泄露模式: 3.已解密的登录请求: 4.HTML注释敏感信息泄露:

  6. Oracle里schema理解

    在Oracle中,一个用户就是一个Schema,表都是建立在Schema中的,也可以理解为每个用户拥有不同的表.一个用户想访问另外一个用户,也就是另外一个schema的表的时候,可以用 usernam ...

  7. Ubuntu14.04.1安装搜狗拼音输入法

    之前在Ubuntu16.04下安装过搜狗,在印象中与这次遇到的问题不一样,因此先说明一下这次Ubuntu的版本号: 参考博客http://blog.csdn.net/tao_627/article/d ...

  8. windows下PTAM的编译

    前些日子在研究PTAM,以下首先说说PTAM的编译过程,我在XP几WIN7搭配vs2010中均已測试过,都能够执行. 首先下载编译PTAM所必须的库文件.下载地址我会给出 PTAM(PTAM.zip) ...

  9. angularjs1-3,工具方法,bootstrap,多个module,引入jquery

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. gemm() 与 gesvd() 到矩阵求逆(inverse)(根据 SVD 分解和矩阵乘法求矩阵的逆)

    可逆方阵 A 的逆记为,A−1,需满足 AA−1=I. 在 BLAS 的各种实现中,一般都不会直接给出 matrix inverse 的直接实现,其实矩阵(方阵)的逆是可以通过 gemm()和gesv ...