zoukankan      html  css  js  c++  java
  • bzoj 4880 [Lydsy1705月赛]排名的战争 贪心

    [Lydsy1705月赛]排名的战争

    Time Limit: 8 Sec  Memory Limit: 256 MB
    Submit: 338  Solved: 69
    [Submit][Status][Discuss]

    Description

    小Q是一名出色的质检员,他负责质检一批手机的质量。手机包含两个性能属性:电池寿命x_1与坚硬度x_2。小Q将
    为它们评估综合质量分数,具体地说,他将选择两个非负实数w_1,w_2,且$_1,w_2不能同时为0,则一部手机的综
    合分数s=w_1*x_1+w_2*x_2。在评定出所有手机的分数后,小Q会把手机按分数从高到低排序,若有多部手机分数相
    同,他可以将它们随意排列,因此每部手机的排名都是独一无二的。聪明的你会发现,对于不同的w的选定,手机
    的最终排名可能会大不一样。因此各个公司都会暗中贿赂小Q,希望他让自己的排名尽量靠前。现一共有n家公司,
    每家公司提供了一部手机用于质检。tangjz知道小Q可以通过调参来控制排名,所以他想知道他的公司的手机排名
    最高是多少,最低是多少。
     

    Input

    第一行包含一个正整数n(1<=n<=100000),即公司的个数。
    接下来n行,每行两个正整数x_1,x_2(1<=x_1,x_2<=1000),分别表示每部手机的两个属性。
    tangjz所在公司提供的手机总是输入里的第一部手机。

    Output

    输出一行两个整数,即最高排名与最低排名。

    Sample Input

    5
    7 7
    11 10
    8 5
    1 1
    12 12

    Sample Output

    3 4

    HINT

     

    Source

    本OJ付费获得

     

    只和w1,w2比值有关,那么就可以固定w2,然后不断调大w1就可以了

     

      1 #include<iostream>
      2 #include<cstdlib>
      3 #include<cstdio>
      4 #include<cstring>
      5 #include<ctime>
      6 #include<cmath>
      7 #include<algorithm>
      8 #include<iomanip>
      9 #include<queue>
     10 #include<map>
     11 #include<bitset>
     12 #include<stack>
     13 #include<vector>
     14 #include<set>
     15 using namespace std;
     16 #define MAXN 100010
     17 #define MAXM 1010
     18 #define INF 1000000000
     19 #define MOD 1000000007
     20 #define ll long long
     21 #define eps 1e-8
     22 struct data{
     23     double v;
     24     int c;
     25     friend bool operator <(data x,data y){
     26         return x.v<y.v;
     27     }
     28 };
     29 int n;
     30 int x[MAXN],y[MAXN];
     31 int low=1,high=INF;
     32 data t[MAXN];
     33 int tot;
     34 int main(){
     35     int i;
     36     scanf("%d",&n);
     37     for(i=1;i<=n;i++){
     38         scanf("%d%d",&x[i],&y[i]);
     39     }
     40     int tlowx=1,thighx=1,tlowy=1,thighy=1;
     41     for(i=2;i<=n;i++){
     42         if(x[i]>x[1]){
     43             thighx++;
     44         }
     45         if(x[i]>=x[1]){
     46             tlowx++;
     47         }
     48         if(y[i]>y[1]){
     49             thighy++;
     50         }
     51         if(y[i]>=y[1]){
     52             tlowy++;
     53         }
     54     }
     55     low=max(low,max(tlowx,tlowy));
     56     high=min(high,min(thighx,thighy));
     57     int tlow=1,thigh=1;
     58     for(i=2;i<=n;i++){
     59         if(y[i]==y[1]){
     60             if(x[i]>=x[1]){
     61                 tlow++;
     62             }
     63             if(x[i]>x[1]){
     64                 thigh++;
     65             }
     66             continue ;
     67         }
     68         if(y[i]<y[1]){
     69             t[++tot].v=1000.*(x[1]-x[i])/(y[i]-y[1]);
     70             t[tot].c=-1;
     71             tlow++;
     72             thigh++;
     73         }
     74         if(y[i]>y[1]){
     75             t[++tot].v=1000.*(x[1]-x[i])/(y[i]-y[1]);
     76             t[tot].c=1;
     77         }
     78         if(t[tot].v<=0){
     79             tlow+=t[tot].c;
     80             thigh+=t[tot].c;
     81             tot--;
     82         }
     83     }
     84     if(tot){
     85         sort(t+1,t+tot+1);
     86         for(i=1;i<=tot;){
     87             int wzh=i;
     88             int tc0=0,tc1=0;
     89             while(wzh<=tot&&fabs(t[wzh].v-t[i].v)<eps){
     90                 if(t[wzh].c==1){
     91                     tc1++;
     92                 }else{
     93                     tc0++;
     94                 }
     95                 wzh++;
     96             }
     97             low=max(low,tlow+tc1);
     98             high=min(high,thigh-tc0);
     99             tlow+=tc1-tc0;
    100             thigh+=tc1-tc0;
    101             i=wzh;
    102         }
    103     }
    104     printf("%d %d
    ",high,low);
    105 }
  • 相关阅读:
    虚拟化、云计算与超融合的简单总结
    期货量化总结与思考
    易盛内外通用版交易API转websocket
    门诊叫号系统系列-1.语音叫号 .net c#
    六线顺上黑马选股和切割线选股法该如何操作?
    我的总结--强势股的短线战法精髓
    MACD头肩顶/底 = 驱动五浪
    有效突破的三三原则
    5日均线--攻击线
    10日均线--操盘线
  • 原文地址:https://www.cnblogs.com/fengzhiyuan/p/8682210.html
Copyright © 2011-2022 走看看