poj 2208

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>

using namespace std;
#define eps 1e-8
struct Point
{
    int x, y;
    int r;
} sta[1010], temp[1010];

int cross(Point a, Point b)
{
    return  a.x*b.y - b.x*a.y;
}

bool cmp(Point a, Point b)
{
    return cross(a, b) > 0;
}
int main()
{
    int n;
    while(scanf("%d",&n) != EOF && n)
    {
        for( int i = 0; i < n; i++)
            scanf("%d%d%d",&sta[i].x, &sta[i].y, &sta[i].r);
        int ans = 0;
        for( int i = 0; i < n; i++)
        {
            Point aim = sta[i];
            int cnt, sum0, sum1;
            cnt = sum0 = sum1 = 0;
            for( int j = 0; j < n; j++)
            {
                if(i==j)continue;
                temp[cnt] = sta[j];
                temp[cnt].x -= aim.x;
                temp[cnt].y -= aim.y;
                if(temp[cnt].y < 0 || (temp[cnt].y == 0 && temp[cnt].x < 0))
                {
                    temp[cnt].x *= -1;
                    temp[cnt].y *= -1;
                    temp[cnt].r = 1 - temp[cnt].r;
                }
                if(temp[cnt].r) sum1++;
                else sum0++;
                cnt++;

            }
            sort(temp, temp + cnt, cmp);
            int cnt0 , cnt1, num0, num1;
            cnt0 = cnt1 = num0 = num1 = 0;
            for( int j = 0, k = 0; j < cnt; j ++)
            {
                //num1 -> 到当前节点之前线前,包括线上的1, num0->到当前节点之气前线前包括线上的0
                if(temp[j].r) num1 ++;
                else num0++;
                while(cross(temp[j], temp[k]) && k < cnt)
                {
                    //cnt1->线前的1,cnt->0线前的0
                    if(temp[k].r)cnt1++;
                    else cnt0++;
                    k++;
                }
                int temp1 = sum0 - num0 + cnt1 + num0 - cnt0 + num1 - cnt1 + 1;
                int temp2 = sum1 - num1 + cnt0 + num0 - cnt0 + num1 - cnt1 + 1;
                ans = max(ans, max(temp1,temp2));
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值