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(n\log n)\)

CO float128 eps=1e-9,pi=acos((float128)-1);
vector ang,val;

int main(){
//	freopen("mine.in","r",stdin),freopen("mine.out","w",stdout);
	int n=read();
	float128 x1=read(),y1=read();
	int same=0;
	val={0,pi/2}; // edit 1
	for(int i=2;i<=n;++i){
		float128 x=read(),y=read();
		if(x==x1 and y==y1) {++same; continue;}
		ang.push_back(atan2(y1-y,x1-x));
		if(pi/2-ang.back()bool{
		return abs(a-b)

你可能感兴趣的:(Gym101174B Bribing Eve)