选美

题目描述

【题目描述】

一年一度的星哥选美又拉开了帷幕

N个人报名参加选拔,每个人都有着各自的相貌参数和身材参数(不大于 10000 的正整数)。你的任务是尽可能让更多人被星哥选中,而唯一要求就是,在这只队伍里面的每个人,都需满足以下不等式:

A (H− h) +B(W− w) ≤ C

其中H和W为这个人的相貌和身材, h和w为选中者中的最小相貌参数和最小身材参数,而A、 B、 C为三个不大于10000 的正的整型常数。

现在请计算星哥最多可以选中多少人。

【输入格式】

第一行:一个整数: N(0<N<=2000)

第二行:三个分开的整数: A,B和C

第三行到第N+ 2行:每行有两个用空格分开的整数,分别表示一个人的相貌参数和身材参数

【输出格式】

第一行:最多被选的人数

【输入样例】

8

1 2 4

5 1

3 2

2 3

2 1

7 2

6 4

5 1

4 3

【输出样例】

5

数据范围比较小,暴力卡过去没问题,AH+BW<=C+Ah+Bw,g=AH+BW,先对g排序,枚举h,w,然后枚举1-n,判断是否符合条件,当g>C+Ah+Bw break;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2005
using namespace std;
int n,A,B,C,Max;
int hh[maxn],ww[maxn];
struct node
{
    int g,h,w;  
}a[maxn];
int g[maxn];
int comp_(const node &a,const node &b){
    return a.g<b.g;
}
int main()
{
    //freopen("beauty.in","r",stdin);
   // freopen("beauty.out","w",stdout);
    //freopen("in.txt","r",stdin);
    scanf("%d%d%d%d",&n,&A,&B,&C);
    for(int i=1;i<=n;i++){  
       scanf("%d%d",&a[i].h,&a[i].w);
       a[i].g=a[i].h*A+a[i].w*B;
       hh[i]=a[i].h;ww[i]=a[i].w;
    }
    sort(a+1,a+n+1,comp_);
    int minh,minw,op=0;
    int ans=0;
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
      if(hh[j]>=hh[i]&&ww[i]>=ww[j]){
        op=0;
        minh=hh[i];minw=ww[j];
        Max=C+minh*A+minw*B;
        for(int k=1;k<=n;k++)
        if(a[k].g>Max) break;
        else if(a[k].w>=minw&&a[k].h>=minh) op++;
        ans=max(ans,op); 
    }
    printf("%d",ans);
    //while(1);
    return 0;
}


posted @ 2017-08-06 20:57  HunterxHunterl  阅读(116)  评论(0编辑  收藏  举报