码迷,mamicode.com
首页 > 其他好文 > 详细

Gym101174B Bribing Eve

时间:2020-06-21 18:14:39      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:determine   rev   时间复杂度   position   push   pre   whether   tin   possible   

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(n\log 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",n-ans+same);
	return 0;
}

Gym101174B Bribing Eve

标签:determine   rev   时间复杂度   position   push   pre   whether   tin   possible   

原文地址:https://www.cnblogs.com/autoint/p/13173239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!