zoukankan      html  css  js  c++  java
  • CF529B Group Photo 2 (online mirror version)

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

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

    • (h_i>maxh)(w_i>maxh),不合法。
    • (h_i>maxh)(w_ileq maxh),必须换。
    • (h_ileq maxh)(w_i>maxh),不能换。
    • (h_ileq maxh)(w_ileq maxh),可换可不换,按 (w_i-h_i) 从大到小贪心选择。

    时间复杂度 (O(n(h+log n)))

    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;
    }
    
  • 相关阅读:
    C# Split 分割字符串
    vim 编辑器命令
    不靠谱的FLOAT数据类型
    linux系统常用命令
    PHP运算方法
    PHP数据类型
    Centos7 系统在安装时指定使用老式网卡命名方式
    PHP代码编写
    PHP变量介绍
    PHP语言介绍
  • 原文地址:https://www.cnblogs.com/May-2nd/p/14370786.html
Copyright © 2011-2022 走看看