Gym-101174B Bribing Eve (象限极角排序)

Bribing Eve
Eve works at a magazine that does product reviews and publishes
recommendations to consumers. They are working on a
new mobile phones review and have decided on two reproducible
tests that score each device's battery lifetime and performance
using an integer between 1 and 1000.
These two scores, x1 and x2, are then combined with a weights
vector w = [w1, w2] to produce an overall score:
s = w1x1 + w2x2 .
The nal review ranking is then obtained by sorting the products
by decreasing order of s. Additionally, when multiple products
get exactly the same score, Eve decides how to order them.
Maria (a fake name to mask her identity) tried to bribe Eve to tweak the results to get her
product higher on the list. Eve argued that she was not able to tamper the evaluation of each
test, but Maria suggested to tweak the weights w used when computing the overall score. The
weights w must be non-negative and at least one of them must be positive, but the values are
decided by Eve.
Eve is thinking whether to modify the weights in Maria's benet or not, and asked you to
determine what are the best and worst possible ranking positions for Maria's product.
Task
Given a list of all products scores in battery and performance [x1, x2] tests, nd out what are
the best and worst positions in the ranking that can be given to Maria's product when the
weights [w1, w2] and the order for tied products are left for Eve to decide.
Input
The rst line has the number N of products being compared. N lines follow, each containing
two integers x1 and x2 indicating a product's score in the battery and performance tests.
Maria's product is the rst on the list.
Constraints
1 ≤ N ≤ 100 000 Number of products
1 ≤ x1, x2 ≤ 1 000 Performance of a product in the tests
SWERC'2016 Universidade do Porto 5
Problem B Problem B
Output
The output consists of two numbers A and B, indicating the best and worst possible positions
that Maria's product can get on the ranking given Eve's ability to modify the weights and
ordering in case of a tie.
Sample Input
5
7 7
11 10
8 5
1 1
12 12
Sample Output

3 4


题解:考虑函数的几何意义,枚举向量,使用象限极角排序+二分查找,其实不用二分也可以。

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const double eps=1e-9;

struct point
{
    int x,y;
}pp[100005];
typedef point Vector;
Vector vc[100005];
int sum1=0,sum2=0,sum3=0,sum4=0;
double dot(Vector a,Vector b)
{
    return 1.0*a.x*b.y-1.0*a.y*b.x;
}


int quad(Vector a)// 判断象限的函数,每个象限包括半个坐标轴
{
    if( a.x>=0 && a.y>0 ) return 1;
    if( a.x<0 && a.y>=0 ) return 2;
    if( a.x<=0 && a.y<0 ) return 3;
    if( a.x>0 && a.y<=0 ) return 4;
}
bool operator < (const Vector &a,const Vector &b)
{
    Vector p1 = a,p2 = b;
    int l1,l2;
    l1 = quad(p1); l2 = quad(p2);
    if( l1 == l2 )
    {
        if(dot(a,b)>0)
            return true;
        else
            return false;
    }
    return l1 < l2;
}

int main()
{
    int n;
    cin>>n;
    int sum5=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&pp[i].x,&pp[i].y);
        vc[i].x=pp[i].x-pp[0].x,vc[i].y=pp[i].y-pp[0].y;
        if(vc[i].x==0&&vc[i].y==0){
            vc[i].x=vc[i].y=1;
            sum5++;
        }
        if(i==0)
            continue;
        if(vc[i].x>=0)
            sum1++;
        if(vc[i].x>0)
            sum2++;
        if(vc[i].y>=0)
            sum3++;
        if(vc[i].y>0)
            sum4++;
    }
    sort(vc+1,vc+n);
    /*for(int i=1;i<n;i++)
        cout<<vc[i].x<<' '<<vc[i].y<<endl;*/
    int ans1=0,ans2=10000000;
    for(int i=1;i<n;i++)
    {
        if((vc[i].x<=0&&vc[i].y>=0))
        {
            //cout<<i<<endl;
            Vector a;
            a.x=-1*vc[i].x,a.y=-1*vc[i].y;
            int c=lower_bound(vc+1,vc+n,a)-vc;
            int d=upper_bound(vc+1,vc+n,a)-vc;
            int now=i;
            if(c>=i)now+=n-1;
            else if(d>=i)now+=n-1;
            //cout<<c<<d<<endl;
            ans1=max((now-c+1)+1,ans1);
            ans2=min((now-d+1-sum5)+1,ans2);
            //cout<<c<<' '<<d<<' '<<i<<' '<<ans1<<' '<<ans2<<endl;
        }
        else
            continue;
    }
    ans1=max(ans1,sum1+1);
    ans1=max(ans1,sum3+1);
    ans2=min(ans2,sum2+1);
    ans2=min(ans2,sum4+1);
    cout<<ans2<<' '<<ans1<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fresh View 不仅是一款图片查看软件,它还可用来播放视频和音频,同时也支持图像转换、打印,并建立HTML相册,Fresh View非常易用,支持86种图像格式,并且100%免费,没有广告条等信息。 支持的格式: 图像格式: Windows位图(*. BMP),Windows图元文件(*. wmf,*. emf等),JPEG图像(*. jpg和*. jpe,*. JPEG格式,*. jfif),CompuServe的GIF图像(*. gif),便携式网络图形图像(*. png),标记图像文件格式的图像(*. tif格式,*. tiff格式),photoshop图像(*. PSD的,*. PDD),TrueVision图像(*.tga,*.win,*.vst,*.vda,*.icb),SGI Images (*.sgi,*.rgb, *.rgba, *.bw), Portable Pixel Map Image (*.ppm), Portable Gray Map Image (*.pgm), Portable Bitmap Image (*.pbm), Autodesk Image (*.cel,*.pic), Kodak Photo-CD Image (*.pcd), Dr. Halo Image (*.cut), Paintshop Pro Image (*.psp) 音频格式: 波形音频(*. WAV),MP3音频(*. mp3),MIDI音频(*.mid,,*.MIDI,*. RMI),Vorbis格式OGG音频(*.ogg),AIFF音频(*. AIF,*. aifc,*. AIFF格式),AU Audio(*.au),ProTracker Mod Audio (*.mod,,*. mdz,*.nst,*. M15),Module Lists Audio (*.mol), Zipped Mod Audio (*.mdz, *.s3z, *.xmz, *.itz), ScreamTracker Mod Audio (*.s3m, *.stm, *.s3z), FastTracker Mod Audio (*.xm, *.xmz), Impulse Tracker Mod Audio (*.it, *.itz), MultiTracker Mod Audio (*.mtm), 模块列表音频med),其他mod音频(*.wow, *.669, *.far, *.okt) 视频格式: AVI视频(*. AVI格式),MPEG视频(*. m1v,*. MP2,*. mp2v,*.mpa,*.mpe,*.MPEG,*. MPG,*. mpv2) 图标资源格式: Windows图标(*. ICO),Windows光标(*.cur),动画光标(*.ani),图标库(*. ICL),可执行文件(*. exe),动态链接库(*. dll文件)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值