CF529B Group Photo 2 (online mirror version)

时间:2021-02-04 12:24:22   收藏:0   阅读:0

日常不搞清楚题意乱写 WA。

看值域这么小,考虑枚举最大高度 \(maxh\)

时间复杂度 \(O\left(n(\max h+\log n)\right)\)

code:

#include<bits/stdc++.h>
using namespace std;
#define Min(x,y)((x)<(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
struct people
{
	int w,h;
}a[1005];
int mn=1000000000,n;
inline bool cmp(people _,people __)
{
	return _.w-_.h>__.w-__.h;
}
void pd(int mx)
{
	int i,sum,tot;
	sum=tot=0;
	For(i,1,n)
	if(a[i].w>mx&&a[i].h>mx)return;
	else if(a[i].h>mx)tot++;
	if(tot>n>>1)return;
	For(i,1,n)
	if(a[i].h>mx)sum+=a[i].h;
	else if(a[i].h<a[i].w&&a[i].w<=mx&&tot<n>>1)tot++,sum+=a[i].h;
	else sum+=a[i].w;
	mn=Min(mn,sum*mx);
}
int main()
{
	int i;
	scanf("%d",&n);
	For(i,1,n)scanf("%d%d",&a[i].w,&a[i].h);
	sort(a+1,a+n+1,cmp);
	For(i,1,1000)pd(i);
	cout<<mn;
	return 0;
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!