标签:out += name return bit clu ret max bool
日常不搞清楚题意乱写 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;
}
CF529B Group Photo 2 (online mirror version)
标签:out += name return bit clu ret max bool
原文地址:https://www.cnblogs.com/May-2nd/p/14370786.html