【POJ 2280】Amphiphilic Carbon Molecules(极角排序+坐标转换+扫描线)

来源:互联网 发布:mac长破折号 编辑:程序博客网 时间:2024/05/21 19:27
Amphiphilic Carbon Molecules
Time Limit: 20000MSMemory Limit: 65536KTotal Submissions: 1577Accepted: 543

Description

Shanghai Hypercomputers, the world’s largest computer chip manufacturer, has invented a new class of nanoparticles called Amphiphilic Carbon Molecules (ACMs). ACMs are semiconductors. It means that they can be either conductors or insulators of electrons, and thus possess a property that is very important for the computer chip industry. They are also amphiphilic molecules, which means parts of them are hydrophilic while other parts of them are hydrophobic. Hydrophilic ACMs are soluble in polar solvents (for example, water) but are insoluble in nonpolar solvents (for example, acetone). Hydrophobic ACMs, on the contrary, are soluble in acetone but insoluble in water. Semiconductor ACMs dissolved in either water or acetone can be used in the computer chip manufacturing process.

As a materials engineer at Shanghai Hypercomputers, your job is to prepare ACM solutions from ACM particles. You go to your factory everyday at 8 am and find a batch of ACM particles on your workbench. You prepare the ACM solutions by dripping some water, as well as some acetone, into those particles and watch the ACMs dissolve in the solvents. You always want to prepare unmixed solutions, so you first separate the ACM particles by placing an Insulating Carbon Partition Card (ICPC) perpendicular to your workbench. The ICPC is long enough to completely separate the particles. You then drip water on one side of the ICPC and acetone on the other side. The ICPC helps you obtain hydrophilic ACMs dissolved in water on one side and hydrophobic ACMs dissolved in acetone on the other side. If you happen to put the ICPC on top of some ACM particles, those ACMs will be right at the border between the water solution and the acetone solution, and they will be dissolved. Fig.1 shows your working situation.

Fig. 1

Your daily job is very easy and boring, so your supervisor makes it a little bit more challenging by asking you to dissolve as much ACMs into solution as possible. You know you have to be very careful about where to put the ICPC since hydrophilic ACMs on the acetone side, or hydrophobic ACMs on the water side, will not dissolve. As an experienced engineer, you also know that sometimes it can be very difficult to find the best position for the ICPC, so you decide to write a program to help you. You have asked your supervisor to buy a special digital camera and have it installed above your workbench, so that your program can obtain the exact positions and species (hydrophilic or hydrophobic) of each ACM particle in a 2D pictures taken by the camera. The ICPC you put on your workbench will appear as a line in the 2D pictures.

Fig. 2

Input

There will be no more than 10 test cases. Each case starts with a line containing an integer N, which is the number of ACM particles in the test case. N lines then follow. Each line contains three integers x, y, r, where (x, y) is the position of the ACM particle in the 2D picture and r can be 0 or 1, standing for the hydrophilic or hydrophobic type ACM respectively. The absolute value of x, y will be no larger than 10000. You may assume that N is no more than 1000. N = 0 signifies the end of the input and need not be processed. Fig.2 shows the positions of ACM particles and the best ICPC position for the last test case in the sample input.

Output

For each test case, output a line containing a single integer, which is the maximum number of dissolved ACM particles.

Sample Input

30 0 00 1 02 2 140 0 00 4 04 0 01 2 17-1 0 01 2 12 3 02 1 10 3 11 4 0-1 2 00

Sample Output

336

Hint


Source

Shanghai 2004






读题就废了老大劲=。=
不过很欣慰能1A

大体意思是二维坐标轴上给了n个坐标。每个点有一个标记0或1
用一条线把平面分成两部分,统计其中一半标记0的点数,另一半标记1的点数,恰在该线上的点都被统计在内。

问怎样分割和统计,点数最多,输出这个点数。

考虑最佳方案一定可以让直线经过某个点。
那么枚举点为基准,然后对其余点进行极角排序,顺时针或者逆时针统计即可。由于极角排序的基准点必须是最左下(纵坐标最小的条件下横坐标最小),因此其余点关于基准点转换一下坐标,同时标记取反一下即可。

代码如下:

#include <iostream>#include <cmath>#include <vector>#include <cstdlib>#include <cstdio>#include <climits>#include <ctime>#include <cstring>#include <queue>#include <stack>#include <list>#include <algorithm>#include <map>#include <set>#define LL long long#define Pr pair<int,int>#define fread(ch) freopen(ch,"r",stdin)#define fwrite(ch) freopen(ch,"w",stdout)using namespace std;const int INF = 0x3f3f3f3f;const int mod = 1e9+7;const double eps = 1e-8;const int MAXN = 1010;struct Point{    int x,y,pos;    Point(){}    Point(int _x,int _y,int _pos = -1):x(_x),y(_y),pos(_pos){}    Point operator -(const struct Point a)const    {        return Point(x-a.x,y-a.y);    }    int operator *(const struct Point a)const    {        return x*a.y-a.x*y;    }};Point pt[MAXN];Point tmp[MAXN];int n;bool cmp(Point a,Point b){    if(a.x == tmp[0].x && a.y == tmp[0].y) return 1;    if(b.x == tmp[0].x && b.y == tmp[0].y) return 0;    return (a-tmp[0])*(b-tmp[0]) >= 0;}int solve(int pos){    //printf("base:(%d,%d)\n",pt[pos].x,pt[pos].y);    int ans = 0;    tmp[0] = pt[pos];    int tp = 1;    int a,b,d,aa,bb;    a = b = d = aa = bb= 0;    d++;    for(int i = 0; i < n; ++i)    {        if(i == pos) continue;        tmp[tp] = pt[i];        if(tmp[tp].y < tmp[0].y)        {            tmp[tp].x = tmp[0].x+(tmp[0].x-tmp[tp].x);            tmp[tp].y = tmp[0].y+(tmp[0].y-tmp[tp].y);            tmp[tp].pos ^= 1;        }        else if(tmp[tp].y == tmp[0].y && tmp[tp].x < tmp[0].x)        {            tmp[tp].x = tmp[0].x+(tmp[0].x-tmp[tp].x);            tmp[tp].pos ^= 1;        }        if(tmp[tp].x == tmp[0].x && tmp[tp].y == tmp[0].y) d++;        else if(tmp[tp].pos) a++;        tp++;    }    sort(tmp+1,tmp+n,cmp);    //for(int i = 0; i < n; ++i)    //{    //  printf("(%d,%d) %d\n",tmp[i].x,tmp[i].y,tmp[i].pos);    //}    for(int i = 0; i < n; ++i)    {        if(tmp[i].x == tmp[0].x && tmp[i].y == tmp[0].y){}        else if(tmp[i].pos == 1)         {            a--;            aa++;        }        else bb++;        if(i == n-1 || (tmp[i]-tmp[0])*(tmp[i+1]-tmp[0]) != 0)        {            //printf("pos:%d a:%d b:%d d:%d aa:%d bb:%d\n",i,a,b,d,aa,bb);            ans = max(ans,d+aa+bb+max(a+b,n-aa-bb-d-a-b));            b += bb;            aa = bb = 0;        }    }    return ans;}int main(){    //fread("");    //fwrite("");    while(~scanf("%d",&n) && n)    {        for(int i = 0; i < n; ++i)            scanf("%d%d%d",&pt[i].x,&pt[i].y,&pt[i].pos);        int ans = 0;        for(int i = 0; i < n; ++i)            ans = max(ans,solve(i));        printf("%d\n",ans);    }    return 0;}
0 0
原创粉丝点击