UVA 10869-brownie Points II (tree array)

Source: Internet
Author: User

UVA 10869-brownie Points II

Topic links

Test instructions: N points on a plane, two persons, first select a line through the vertical x-axis of the point. And then there's a guy who crosses the line on this wire. Select a line that is perpendicular to the line, then divide the 4 quadrants, and the first person gets a score of 1. 3 quadrants, and the second person is 24 quadrants. Ask the first person according to the optimal way, can get the maximum value of the minimum score, and this value there is a person's score possible situation

Idea: Tree-like array, can enumerate a point, suppose can find the right upper and lower left point number is good, its useful a tree-like array, the y-coordinate discretization, and then recorded in, and then put the point x from left to right, each time after the deletion of points to query the current height of the number of points, so that you can get the number of upper right corner, The same can be asked to the lower left corner, can handle this step is good to run. Finally pay attention to the answer to take weight and increment, with set on OK

Code:

#include <cstdio> #include <cstring> #include <algorithm> #include <set>using namespace std;#    Define Lowbit (x) (x& (×)) const int N = 200005;struct point {int x, y, rank, ans, Mi; int xn, yn;}    P[n];int bit[n];set<int> out;void Add (int x, int v) {while (X < N) {Bit[x] + = v;x + = lowbit (x);    }}int get (int x) {int ans = 0;    while (x > 0) {ans + = bit[x];x-= lowbit (x); } return ans; int get (int l, int r) {return get (R)-Get (L-1);} BOOL Cmpy (Point A, point B) {return a.y < b.y;}    BOOL Cmpx (Point A, point B) {if (a.x = = b.x) return a.y > B.y; return a.x < b.x;}    BOOL Cmpx2 (Point A, point B) {if (a.x = = b.x) return A.Y < b.y; return a.x > b.x;}    int N, top;void init () {memset (bit, 0, sizeof (bit));    for (int i = 0; i < n; i++) {scanf ("%d%d", &p[i].x, &p[i].y);p [I].ans = 0;p[i].xn = P[i].yn = 0; } sort (p, p + N, cmpy);}    void Solve () {top = 1; for (int i = 0; i < n; i++) {iF (i && p[i].y! = p[i-1].y) top++;p [I].rank = Top;add (P[i].rank, 1);  } for (int i = 0; i < n; i++) {int J;int len = 0;for (j = i; p[i].y = = P[j].y && J < N; j + +) Len++;for    (j = i; p[i].y = = P[j].y && J < N; j + +) P[j].yn = Len;i = j-1;    } sort (p, p + N, cmpx);    for (int i = 0; i < n; i++) {Add (P[i].rank,-1);p [I].ans + = Get (P[i].rank + 1, top);  } for (int i = 0; i < n; i++) {int J;int len = 0;for (j = i; p[i].x = = p[j].x && J < N; j + +) Len++;for    (j = i; p[i].x = = p[j].x && J < N; j + +) P[j].xn = Len;i = j-1;    } memset (bit, 0, sizeof (bit));    for (int i = 0; i < n; i++) Add (P[i].rank, 1);    Sort (p, p + N, cmpx2);    for (int i = 0; i < n; i++) {Add (P[i].rank,-1);p [I].ans + = Get (1, p[i].rank-1);    } for (int i = 0; i < n; i++) {int J;int Min = 1000000000;for (j = i; p[i].x = = p[j].x && J < N; j + +) min = min (min, P[j].ans); for (j = i; p[i].x = = p[j].x && J < N; J + +) P[j].    Mi = Min;i = j-1;    } int Max = 0;    Out.clear (); for (int i = 0; i < n; i++) {if (P[i].    Mi! = P[i].ans) continue;if (P[i].ans > Max) {max = P[i].ans;    Out.clear (); Out.insert (N-p[i].ans-p[i].xn-p[i].yn + 1);}    else if (P[i].ans = = Max) {Out.insert (N-p[i].ans-p[i].xn-p[i].yn + 1);} } printf ("Stan:%d;    Ollie: ", Max);    for (Set<int>::iterator it = Out.begin (); It! = Out.end (); it++) printf ("%d", *it); printf ("; \ n");}    int main () {while (~SCANF ("%d", &n) && N) {init (); solve (); } return 0;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

UVA 10869-brownie Points II (tree array)

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.