码迷,mamicode.com
首页 > 其他好文 > 详细

Amphiphilic Carbon Molecules

时间:2014-12-12 22:18:08      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   io   ar   color   os   sp   for   

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.

bubuko.com,布布扣

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.

bubuko.com,布布扣

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

3 
0 0 0 
0 1 0 
2 2 1 
4 
0 0 0 
0 4 0 
4 0 0 
1 2 1 
7 
-1 0 0 
1 2 1 
2 3 0 
2 1 1 
0 3 1 
1 4 0 
-1 2 0 
0

Sample Output

3 
3 
6

<span style="font-size:14px;"># include <cstdio>
# include <cmath>
# include <cstring>
# include <algorithm>
using namespace std;

const int maxn = 1000 + 5;

struct Point
{
    int x,y;
    double rad;
    bool operator <(const Point &n) const
    {
        return rad<n.rad;
    }
}op[maxn], p[maxn];

int n, color[maxn];

bool Left(Point a,Point b)    //判断点是不是在线段的左边
{
    return a.x*b.y-a.y*b.x >= 0;
}

int solve()
{
    int i,j;
    if(n<=2)    return 2;
    int ans=0;

    for(i=0;i<n;i++)
    {
        int k=0;
        for(j=0;j<n;j++)
        {
            if(j!=i)
            {
                p[k].x=op[j].x-op[i].x;
                p[k].y=op[j].y-op[i].y;
                if(color[j]) { p[k].x = -p[k].x; p[k].y = -p[k].y; }
                p[k].rad=atan2(p[k].y,p[k].x);    //求弧度值,其中atan2(y ,x);
                k++;
            }
        }
        sort(p,p+k);    //根据弧度排序

        int l=0,r=0,cnt=2;    //扫描法,以两点为一条直线,扫描左边的点;
        while(l<k)
        {
            if(l==r)    { r=(r+1)%k; cnt++; }
            while(r!=l&&Left(p[l],p[r]))    { r=(r+1)%k; cnt++; }     //扫半平面;
            cnt--;
            l++;
            ans= ans >= cnt ? ans : cnt;
        }
    }
    return ans;
}

int main()
{
    //freopen("a.txt","r",stdin);
    while(scanf("%d", &n) == 1 && n)
    {
        int i;
        for(i=0;i<n;i++)
            scanf("%d%d%d",&op[i].x,&op[i].y,&color[i]);
        printf("%d\n",solve());
    }
    return 0;
}</span>


Amphiphilic Carbon Molecules

标签:des   style   http   io   ar   color   os   sp   for   

原文地址:http://blog.csdn.net/rechard_chen/article/details/41898585

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!