[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实现箭头、关闭按钮旋转效果
说起css3的旋转效果,那就要说为什么不用js去实现,CSS3的动画效果,能够减少对JavaScript和Flash文件的HTTP请求这是原因之一.但是css3可能要求浏览器执行很多的工作来完成这个动 ...
- nyoj252-01串
01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有"11"子串的这种长度的0 ...
- 邓_ php SESSION
学会php session可以在很多地方使用,比如做一个后台登录的功能,要让程序记住用户的session,其实很简单,看了下面的文章你就明白了. PHP session用法其实很简单它可以把用户提交的 ...
- hdu 1542 线段树之扫描线之面积并
点击打开链接 题意:给你n个矩形,求它们的面积,反复的不反复计算 思路:用线段树的扫描线完毕.将X坐标离散化后,从下到上扫描矩形,进行各种处理,看代码凝视把 #include <stdio.h& ...
- Android自己定义对话框实现QQ退出界面
效果 首先看下qq的效果图,点击菜单button后点退出就会出现如图的对话框. 从上图能够看出,该对话框有一个圆角,以及标题,提示信息,两个button,button颜色是白色,button点击后背景 ...
- 《学习opencv》笔记——基本数据结构,CvMat,矩阵訪问
老板让让做一个东东.输入端要用到opencv顺便就来学习一下.买了本书<学习opencv>翻来一看,opencv1.0,去官网上一看.opencv2.49,瞬间有种蛋碎的赶脚.看着 ...
- 宝马男砍人不慎刀落反被杀 防卫过当or故意伤害(在生命受到威胁的情况下,已经很难判断对方意图了,而且假如于莫是老弱妇幼,可能现在死的就是于莫了)
如果被砍的是周律师他就不会说是防为过当吧,宝马车主跑回自己的车边时最危险,不知道他车上还有什么刀枪之类的.这如果判防卫过当,恶人会更恶,老实人连防卫都不敢了. 不知道在这个没有法治的国家会是如何判案的 ...
- Unable to access the IIS metabase
https://stackoverflow.com/questions/12859891/error-unable-to-access-the-iis-metabase 解决方法1 On Window ...
- python fuzzy c-means demo
摘自:http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_cmeans.html#example-plot-cmeans-py,加入了自己的 ...
- 25.QT进度条
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> 5 #include <QProgressBar&g ...