[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 ...
随机推荐
- react实现简单倒计时
今天遇到一个简单的小功能,看网上的一些方法感觉不太适合,所以就手敲了一个,直接上代码!!! import React, { Component } from 'react'; class NoTime ...
- [USACO17JAN] Promotion Counting晋升者计数 (树状数组+dfs)
题目大意:给你一棵树,求以某节点为根的子树中,权值大于该节点权值的节点数 本题考查dfs的性质 离散+树状数组求逆序对 先离散 我们发现,求逆序对时,某节点的兄弟节点会干扰答案 所以,我们在递推时统计 ...
- ❝ Windows系统的FTP上传下载脚本 ❞
运行环境:windows 脚本功能:从目标系统下载数据库备份文件*.dmp 执行方法:windows任务计划定时调用文件ftp.bat 文件1:ftp.bat echo 开始备份日期: >> ...
- codevs——T1048 石子归并
http://codevs.cn/problem/1048/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Descriptio ...
- iOS-为方便项目开发在pch加入一些经常使用宏定义
1.关于NSLog输出 /** * 当Xcode为Release时不输出,为Debug时输出 * * @param ... * * @return */ #ifndef __OPTIMIZE__ #d ...
- ShareREC for iOS v1.0.4 已经公布
ShareREC for iOS v1.0.4 已经公布 版本号:v1.0.4 2015-3-13 1.新增视频列表的筛选排序功能 2.修复在開始录制后,没有调用结束录制直接进入社区崩溃问题 3.优化 ...
- code::blocks配置编译cuda并进行第一个demo的測试
我们先新建个NVCC的编译器. 使用复制GCC编译器的方式进行新建,然后我们进行下面的路径配置 先来看看链接库,将我们常常使用的cuda库链接进来. 然后链接cuda的头文件: 接着配置调试工具以及编 ...
- 精美viso制图(1)
office组件中的viso是一款十分强大的绘图工具,在绘制流程图.结构框图时显得十分方便,这里将我自己绘制的一些viso图(大部分都是用在我自己的论文中的)与大家分享一把. 1.深度学习训练流程图 ...
- 0x11 栈
这个不难吧,算是常识了..毕竟也是刷过USACO的人 对顶栈这东西前几天才遇到过,好像和在线求中位数那东西放一起了吧 单调栈倒是没什么...贴个代码算了.一开始有点蠢的每个位置算,后来发现出栈再算就行 ...
- 风暴英雄 http 302重定向 正在等待游戏模式下载完成
抓包 在抓到的数据包里面,看到一个http get请求,右键选中,然后follow stream wireshark自动进行数据包过滤tcp.stream eq 1340,并且可以看到完整的数据通讯 ...