[CodeForces]529B Group Photo 2
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的更多相关文章
- CF 529B Group Photo 2 (online mirror version)
传送门 解题思路 这道题要用到贪心的思路,首先要枚举一个h的最大值,之后check.如果这个东西的w[i]与h[i]都大于枚举的值就直接return false,如果w[i]比这个值小,h[i]比这个 ...
- A1109. Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT A1109 Group Photo (25 分)——排序
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 1109 Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 1109 Group Photo (25 分)
1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...
- PAT 1109 Group Photo[仿真][难]
1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of for ...
- 1109. Group Photo (25)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT 1109 Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT_A1109#Group Photo
Source: PAT A1109 Group Photo (25 分) Description: Formation is very important when taking a group ph ...
随机推荐
- css3 3d 魔方
<style><!--@charset "UTF-8"; * { margin: 0; padding: 0 } html,body{ width: 100%; ...
- 基于Tags的简单内容推荐的实现
原来为了简单方便,自己小网站上的文章页的相关内容推荐就是从数据库里随机抽取数据来填充一个列表,所以一点相关性都没有,更本没有办法引导用户去访问推荐内容. 算法选择 如何能做到相似内容的推荐呢,碍于小网 ...
- VLC编译
http://blog.csdn.net/hdh4638/article/details/7602321 1 下载代码 ki.videolan.org/VLC_Source_code git colo ...
- ioremap映射函数
一.ioremap() 函数 Linux在io.h头文件中声明了函数ioremap(),用来将I/O内存资源的物理地址映射到核心虚地址空间(3GB-4GB)中(这里是内核空间),原型如下: 1.ior ...
- mobile touch 备用
var _scrollIndex=1; function scrollPage(){ var _contentEle = $('.view-container'),_viewEle = _conten ...
- Ajax jQuery下拉框联动案例
需求: 使用ajax和jQuery实现下拉框联动. 注意:需要加入jquery-2.1.1.min.js 前台 <!DOCTYPE html> <html> <head& ...
- intel dpdk在ubuntu12.04中測试testpmd、helloworld程序
一.測试环境 操作系统:ubuntu12.04 x86_64 dpdk版本号:1.6.0r2 虚拟机:vmware 10 网卡: Intel Corporation 82545EM Gigabit ...
- jQuery验证所有输入合法后才干提交
大学三年里所有在专注后台编码.学会不知多少种,servlet.ssh,springMVC,web.py...... 最后每次碰到前端自己要写点东西就满目愁抑, 干脆自己好好理解一段前端代码, 特地拿出 ...
- memcached—向memcached中保存Java实体需注意的问题
今天以代码实例的形式总结一下向memcached中保存Java实体需注意的问题: memcached工具类代码: package com.ghj.packageoftool; import java. ...
- Java測试覆盖率工具----Cobertura,EclEmma
Cobertura 是一个与Junit集成的代码覆盖率測量工具 它是免费.开源的 它能够与Ant和Maven集成.也能够通过命令行调用 能够生成HTML或XML格式的报告 能够依照不同的标准对HTML ...