1606-amphiphilic Carbon molecules (extreme angle sort)

Source: Internet
Author: User

The key to this problem is to use the method of the polar sort, enumerate a fixed point, the other points for the original heart to find the angle, and then sort, the number of points to convert how many degrees. Because the angle is orderly, you can use a sweep to find the maximum value. In addition, the use of a small trick, that is, the use of symmetry, the one side of the black point into the white point on the other side, so that only the number of white points to be good.

It is noteworthy that, in order to form that dividing line, we enumerate two angles (that is, the point in the new coordinate system of the original heart from the Datum point), so that the angle between them is not more than 180 °, in order to make the dividing lines rotate 360 °, we enumerate the L variable to the last point and then stop, so the R variable is Cnt


, because the black point symmetry has been transformed to the other side, the number of points within this acute angle range is the answer. This is equivalent to a not straight bezel.

#include <bits/stdc++.h>using namespace Std;const int maxn = n + 5;int n;struct point{int x,y,col;    Double rad;    BOOL operator < (const point &r) const {return rad < R.rad; }}p[maxn],op[maxn];bool X (int l,int r) {return p[l].x*p[r].y-p[l].y*p[r].x >= 0;} int main () {while (~SCANF ("%d", &n) &&n) {for (int i=0;i<n;i++) scanf ("%d%d%d", &op[i].y,&op[i        ].X,&AMP;OP[I].COL);        if (n<=2) {printf ("%d", n); continue;}        int ans = 0;            for (int i=0;i<n;i++) {int cnt = 0;                    for (int j=0;j<n;j++) {if (i!=j) {p[cnt].x = op[j].x-op[i].x;                    P[cnt].y = OP[J].Y-OP[I].Y;                        if (Op[j].col = = 1) {p[cnt].x =-p[cnt].x;                    P[cnt].y =-P[CNT].Y;                    } P[cnt].rad = atan2 (p[cnt].y,p[cnt].x);                cnt++;       }            }     Sort (p,p+cnt);            int sum = 2,l = 0,r = 0;  while (L < CNT) {if (l==r) {r = (r+1)%cnt; sum++;}                 In order to enumerate 360°while (L!=r&&x (l,r)) {r = (r+1)%cnt; sum++; } l++;            When exceeding 180°, the sum--;//minus the point in the acute angle ans = max (ans,sum);    }} printf ("%d\n", ans); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

1606-amphiphilic Carbon molecules (extreme angle sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.