Poj 2280 & HDU 1661 amphiphilic carbon molecules

Source: Internet
Author: User

Question:

There are some points on the plane. Each point has a property of 0, 1. A straight line is required to divide the plane into two parts. Some of them take the vertices whose property is 0, and the other part take the vertices whose property is 1. If all the points are removed from the straight line, you can ask how many points can be taken at most.



Solution:

Scan line algorithm. Enumerate any point. Other points are sorted according to that point. Scan to obtain the maximum value.



Note:

1. Because the atan2 method has an accuracy error in the polar sorting, you need to use the Cross Product Method to sort it here. Otherwise, you can test the accuracy slowly!

2. vertices in cross-product sorting must be sorted into two quadrants in advance. Note the status transition of the point attribute.

3. Weak poj data and strong HDU data. Both OJ and C ++ are slow.


The following code is used:

# Include <set> # include <map> # include <queue> # include <math. h> # include <vector> # include <string> # include <stdio. h> # include <string. h> # include <stdlib. h >#include <iostream> # include <algorithm> # define EPS 1e-8 # define PI ACOs (-1.0) # define INF 107374182 # define inf64 1152921504606846976 # define LC l, m, tr <1 # define RC m + 1, R, TR <1 | 1 # define iabs (x)> 0? (X):-(x) # define clear1 (A, X, size) memset (A, X, sizeof (A [0]) * (size )) # define clearall (A, x) memset (A, X, sizeof (A) # define memcopy1 (A, X, size) memcpy (A, X, sizeof (X [0]) * (size) # define memcopyall (A, x) memcpy (A, X, sizeof (x) # define max (x, y) (x)> (y ))? (X): (y) # define min (x, y) (x) <(y ))? (X): (y) using namespace STD; int N, pointnum, ANS, CNT, L, R, sum, num, P; struct node1 {int x, y, sta;} Point [1005], temp [1005]; int detmul (const node1 A, const node1 B) {return. x * B. y-B. x *. y;} bool CMP (const node1 A, const node1 B) {return detmul (a, B)> 0;} int main () {While (scanf ("% d ", & N), n) {for (INT I = 0; I <n; I ++) {scanf ("% d", & point [I]. x, & point [I]. y, & point [I]. sta);} ans = 0; For (pointnum = 0; pointn Um <n; pointnum ++) {CNT = 0; For (INT I = 0; I <n; I ++) {if (I = pointnum) continue; temp [CNT]. X = point [I]. x-point [pointnum]. x; temp [CNT]. y = point [I]. y-point [pointnum]. y; temp [CNT]. sta = point [I]. sta; If (temp [CNT]. Y <0 | (temp [CNT]. y = 0 & temp [CNT]. x <0) {temp [CNT]. x * =-1; temp [CNT]. y * =-1; temp [CNT]. sta =! Temp [CNT]. sta;} CNT ++;} Sort (temp, temp + CNT, CMP); L = 0; r = 0; sum = 0; For (INT I = 0; I <CNT; I ++) {If (temp [I]. sta = 0) l ++;} For (INT I = 0; I <CNT; I = P) {num = 0; For (P = I; P <CNT; P ++) {If (detmul (temp [I], temp [p]) break; If (temp [p]. sta) r ++; else num ++;} sum = max (sum, L + R + 1); sum = max (sum, CNT-l-R + p-I + 1); L-= num;} ans = max (ANS, sum);} printf ("% d \ n ", ans);} return 0 ;}


Poj 2280 & HDU 1661 amphiphilic carbon molecules

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.