Gym-101670j punching power (Maximum Independent Set)

Source: Internet
Author: User

Question:

The park management finally decided to install some popular boxing machines at varous strategic places in the park. in fact, to compensate for the previous lack of machines, they decided to install as your machines as possible. surprisingly enough, the park is not going to be choked with new machines because there are some quite serous legal limitations regarding the locations of the machines. the management has marked all possible boxing machine locations and their respective coordinates on the park plan. additionally, they also have to respect manufacturer security rule: the distance between any two boxing machines has to be at least 1.3 meters.

Help the management to establish the maximum possible number of boxing machines which can be installed in the park.

Input specification:

There are several test cases. each case starts with a line containing one integer n which specifies the number of possible boxing machine locations in the park (1 ≤ n ≤ 2000 ). next, there are n lines representing the location coordinates, each line describes one location by a pair of integer coordinates in meters. all locations in one test case are unique. each coordinate is non-negative and less than or equal to 109.

You are guaranteed that all locations form a single connected group, that is, it is possible to start in any location and reach any other location by a sequence of steps, each of which changes exactly one coordinate by 1, without leaving the area suitable for placing boxing machines.

Output specification:

For each test case, print a single line with one integer representing the maximum number of boxing machines which can be installed in the park.

Ideas:

Let's talk about it first:

The distance between any two boxing machines has to be at least 1.3 meters. Is this sentence useless ????

The graph creation rule is based on the sentence each of which changes exactly one coordinate by 1, which is, and is automatically closed.

First, create the graph, and then find the maximum independent set. The maximum independent set = the number of vertices-the maximum number of matching points.

Summarize the reasons for the problem:

Understanding of Hungary algorithms is too simple!

Not refined!

Code:

 

# Include <bits/stdc ++. h ># define INF 0x3f3fusing namespace STD; typedef long ll; const int maxn = 3000; struct node {int X, Y;} node [maxn]; vector <int> V [maxn]; int N, vis [maxn], linker [maxn]; bool DFS (int u) {for (INT I = 0; I <V [u]. size (); I ++) // each point connected to U {int _ v = V [u] [I]; // put it in the alternating path if (! Vis [_ v]) {vis [_ v] = 1; if (linker [_ v] = 0 | DFS (linker [_ v]) // if it is an unmatched vertex, the alternating path is an augmented path. The switching path {linker [_ v] = u; linker [u] = _ v; return true ;}}} return false;} int match () {int res = 0; memset (linker, 0, sizeof (linker); For (INT I = 0; I <N; I ++) {memset (VIS, 0, sizeof (VIS); If (linker [I] = 0 & DFS (I) RES ++ ;} return res;} int main () {While (scanf ("% d", & N )! = EOF) {for (INT I = 1; I <= N; I ++) {scanf ("% d", & node [I]. x, & node [I]. y) ;}for (INT I = 1; I <= N; I ++) {v [I]. clear (); For (Int J = 1; j <= N; j ++) {If (ABS (node [I]. x-node [J]. x) + ABS (node [I]. y-node [J]. y) = 1) {v [I]. push_back (j) ;}}int ans = match (); // cout <"Ans:" <ans <Endl; printf ("% d \ n ", n-ans);} return 0 ;}
View code

 

Gym-101670j punching power (Maximum Independent Set)

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.