Codeforces 97b superset plane governance

Source: Internet
Author: User

Question link: Click the open link

Question:

Given a Point Set

Add some points before gathering them.

After adding a vertex, any two vertices in the vertex set must satisfy at least one of the following two vertices.

1. On the same horizontal line or on the same vertical line

2. There are other points in the enclosed matrix.

Ideas:

Plane governance

First, sort the points by the X axis, find the center point, and create a straight line x = A [Mid]. X;

Then all vertices are projected onto this line, so the left vertices do not need to be matched with the right.


#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <algorithm>#include <iostream>#include <set>#include <queue>#include <cstring>using namespace std;typedef long long ll;typedef pair<int,int> pii;const int inf = 1e9;template <class T>inline bool rd(T &ret) {    char c; int sgn;    if(c=getchar(),c==EOF) return 0;    while(c!='-'&&(c<'0'||c>'9')) c=getchar();    sgn=(c=='-')?-1:1;    ret=(c=='-')?0:(c-'0');    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');    ret*=sgn;    return 1;}template <class T>inline void pt(T x) {    if (x <0) {        putchar('-');        x = -x;    }    if(x>9) pt(x/10);    putchar(x%10+'0');}#define N 10005pii a[N], b[N*20];int top, n;void dfs(int l, int r){    int mid = (l+r)>>1, maxx = a[mid].first;    for(int i = l; i <= r; i++)        b[top++] = pii(maxx, a[i].second);    if(l < mid)        dfs(l, mid-1);    if(mid < r)        dfs(mid+1, r);}void input(){    for(int i = 1; i <= n; i++) rd(a[i].first), rd(a[i].second);    sort(a+1, a+1+n);    top = 0;}void output(){    sort(b, b+top);    top = unique(b, b+top)-b;    pt(top); putchar('\n');    for(int i = 0; i < top; i++)        pt(b[i].first), putchar(' '), pt(b[i].second), putchar('\n');}int main(){    while(rd(n)){        input();        dfs(1, n);        output();    }    return 0;}


Codeforces 97b superset plane governance

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.