zoukankan      html  css  js  c++  java
  • Gym101174B 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, (x_1) and (x_2), are then combined with a weights vector (w = [w_1, w_2]) to produce an overall score:

    [s = w_1x_1 + w_2x_2 ]

    The final 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 benefit or not, and asked you to determine what are the best and worst possible ranking positions for Maria's product.

    (1 ≤ N ≤ 100 000), Number of products

    题解

    做差,那么(1)(i)优的条件是

    [x_w(x_1-x_i)+y_w(y_1-y_i)geq 0 ]

    ((x_w,y_w))((x_1-x_i,y_1-y_i))看成向量,那么这就是点积。所以对于某个((x_w,y_w)),它左右(frac{pi}{2})范围内的点都满足(1)(i)优。

    那么极角排序搞个双指针即可。时间复杂度(O(nlog n))

    CO float128 eps=1e-9,pi=acos((float128)-1);
    vector<float128> ang,val;
    
    int main(){
    //	freopen("mine.in","r",stdin),freopen("mine.out","w",stdout);
    	int n=read<int>();
    	float128 x1=read<float128>(),y1=read<float128>();
    	int same=0;
    	val={0,pi/2}; // edit 1
    	for(int i=2;i<=n;++i){
    		float128 x=read<float128>(),y=read<float128>();
    		if(x==x1 and y==y1) {++same; continue;}
    		ang.push_back(atan2(y1-y,x1-x));
    		if(pi/2-ang.back()<eps and ang.back()-pi<eps) val.push_back(ang.back()-pi/2);
    		if(-pi/2-ang.back()<eps and ang.back()<eps) val.push_back(ang.back()+pi/2);
    	}
    	n-=same; // edit 2
    	sort(ang.begin(),ang.end());
    	sort(val.begin(),val.end());
    	val.erase(unique(val.begin(),val.end(),[&](float128 a,float128 b)->bool{
    		return abs(a-b)<eps;
    	}),val.end());
    	int l=0,r=-1,ans=0;
    	for(float128 v:val){
    		float128 d=v-pi/2,u=v+pi/2;
    		for(;r+1<(int)ang.size() and ang[r+1]-u<eps;++r);
    		for(;l<=r and ang[l]-d<-eps;++l);
    		ans=max(ans,r-l+1);
    //		cerr<<"l1="<<l<<" r1="<<r<<endl;
    	}
    	printf("%d ",n-ans);
    	l=0,r=-1,ans=n;
    	for(float128 v:val){
    		float128 d=v-pi/2,u=v+pi/2;
    		for(;r+1<(int)ang.size() and ang[r+1]-u<-eps;++r);
    		for(;l<=r and ang[l]-d<eps;++l);
    		ans=min(ans,r-l+1);
    //		cerr<<"l2="<<l<<" r2="<<r<<endl;
    	}
    	printf("%d
    ",n-ans+same);
    	return 0;
    }
    
  • 相关阅读:
    java 构造函数内部的多态方法 完全剖析
    Android 高仿微信 获取最近刚刚拍照的缩略图 功能实现
    Android 高仿豌豆荚 一键安装app 功能 实现
    Android Bitmap实战技巧
    Android 异步加载神器Loader全解析
    Android 开源项目PhotoView源码分析
    细数Android开源项目中那些频繁使用的并发库中的类
    js 压缩图片 H5
    上传从剪贴板复制的图片
    moble 设备多指手势识别 (tap , double_tap , pinch)
  • 原文地址:https://www.cnblogs.com/autoint/p/13173239.html
Copyright © 2011-2022 走看看