UVA1606 Amphiphilic Carbon Molecules

选定一个点作为基点,依次求出每个点的极角并排序,虚拟出一条直线开始旋转,动态统计两侧黑白点的个数。

#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#define maxn 100000+10
using namespace std;
int n;
struct node
{
    int x,y,cl;
    double rad;
    node(int x=0,int y=0):x(x),y(y) {}
    bool operator <(const node &a)const
    {
        return rad<a.rad;
    }
} p[maxn],st[maxn];
node operator -(const node &a,const node &b)
{
    return node(a.x-b.x,a.y-b.y);
}
int Cross(const node &a,const node &b)
{
    return (a.x*b.y-b.x*a.y);
}
int solve()
{
    int maxx=0;
    for(int i=0; i<n; i++)
    {
        int k=0;
        for(int j=0; j<n; j++)
            if(i!=j)
            {
                p[k]=st[j]-st[i];
                if(st[j].cl)//技巧性,以基点为中心对称,这样统计的黑白点就可以在一侧统计
                {
                    p[k].x=-p[k].x;
                    p[k].y=-p[k].y;
                }
                p[k].rad=atan2(p[k].y,p[k].x);
                k++;
            }
        sort(p,p+k);

        int l=0,r=0,cnt=2;
        for(;l<k;l++)
        {
            if(l==r)
            {
                r=(r+1)%k;
                cnt++;
            }
            while(l!=r&&Cross(p[l],p[r])>=0)
            {
                r=(r+1)%k;
                cnt++;
            }
            cnt--;
            maxx=max(maxx,cnt);
        }
    }
    return maxx;
}
int main()
{
    while(scanf("%d",&n)&&n)
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d %d %d",&st[i].x,&st[i].y,&st[i].cl);
        }
        printf("%d\n",solve());
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值