#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;
}
poj 2208
最新推荐文章于 2019-07-11 16:57:12 发布