Codeforces Gym 101174 B Within Arm's Reach 极角排序

Posted polya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Gym 101174 B Within Arm's Reach 极角排序相关的知识,希望对你有一定的参考价值。

#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn=1e5+10;
struct point{
    double x,y;
    void in()
    {
        scanf("%lf%lf",&x,&y);
    }
    inline point f(point a)const{
        if(a.x<=0&&a.y>=0)
            a.x=-a.x,a.y=-a.y;
        return a;
    }
    double operator <(const point &a)const
    {
        return f(*this)*f(a)>0;
    }
    double operator*(const point &a)const
    {
        return x*a.y-y*a.x;
    }
    void out()
    {
        printf("%f %f
",x,y);
    }
};

int same=0,biger=0,tmp=0;
vector<point>q;
void init()
{

    int n;
    scanf("%d",&n);
    double x,y;
    scanf("%lf%lf",&x,&y);
    point t;
    for(int i=1;i<n;i++)
    {
        t.in();
        t.x-=x;t.y-=y;
        if(!t.x&&!t.y) same++;
        else if(t.x>0&&t.y>0) biger++;
        else if(t.x<0&&t.y<0);
        else {
            q.push_back(t);
            if(t.x>=0&&t.y<=0) tmp++; //4th quadrant
        }
    }
}
void solve()
{
    sort(q.begin(),q.end()); //把排序做好就基本上没问题了 
//    for(auto i:q)
//        i.out();
//    printf("%d
",q.size());
    int mx=0,mn=biger+tmp;
    for(int i=0,j,sz=q.size();i<sz;i=j)
    {
        int l=0,r=0;
        for(j=i;j<sz&&q[j]*q[i]==0;j++)
        {
            if(q[j].y>0||q[j].y==0&&q[j].x<0) l++;
            else r++;
        }
//        printf("%d %d %d %d
",i,j,l,r);
        mx=max(mx,biger+same+tmp+l);
        mn=min(mn,biger+tmp-r);
        tmp+=l-r;
    }
    printf("%d %d
",mn+1,mx+1);
}
int main() {
  //  freopen("in.txt","r",stdin);

    init();
    solve();
  return 0;
}

 

以上是关于Codeforces Gym 101174 B Within Arm's Reach 极角排序的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Gym 101174 J Risky Lottery 计算方法 逼近求值 dfs

Codeforces Gym 101174 I The White Rabbit Pocket Watch 模线性方程组

Gym 101174D Dinner Bet(概率DP)题解

Passwords Gym - 101174E

Gym101174B Bribing Eve

状压dp Gym - 100676G