Typesetting math: 100%

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, x1 and x2, are then combined with a weights vector w=[w1,w2] to produce an overall score:

s=w1x1+w2x2

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.

1N100000, Number of products

题解

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

xw(x1xi)+yw(y1yi)0

(xw,yw)(x1xi,y1yi)看成向量,那么这就是点积。所以对于某个(xw,yw),它左右π2范围内的点都满足1i优。

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

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;
}

posted on   autoint  阅读(199)  评论(0编辑  收藏  举报

编辑推荐:
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
阅读排行:
· 开发的设计和重构,为开发效率服务
· 从零开始开发一个 MCP Server!
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Ai满嘴顺口溜,想考研?浪费我几个小时
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
历史上的今天:
2019-06-21 「NOI2017」蚯蚓排队
2019-06-21 「NOI2018」情报中心

导航

点击右上角即可分享
微信分享提示