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;
    }
    
  • 相关阅读:
    SSH免密码登录
    Qt编译错误GL/gl.h: No such file or directory
    UVA 11645
    《逆袭大学》文摘——9.4 基础和应用的平衡中找到大学的节奏
    EBS採购模块中的高速接收和高速接收事务
    笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
    git 冲突解决的方法
    SICP 习题 (1.43)解题总结
    Swift百万线程攻破单例(Singleton)模式
    setjmp/longjmp
  • 原文地址:https://www.cnblogs.com/autoint/p/13173239.html
Copyright © 2011-2022 走看看