Gym - 101670J Punching Power(最大獨立集)

來源:互聯網
上載者:User

標籤:possible   路徑   ase   tween   names   isp   other   ==   open   

題目:

The park management finally decided to install some popular boxing machines at various strategic places in the park. In fact, to compensate for the previous lack of machines, they decided to install as many machines as possible. Surprisingly enough, the park is not going to be choked with new machines because there are some quite serious 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.

思路:

先吐槽一下:

The distance between any two boxing machines has to be at least 1.3 meters.這句話難道沒有用????

建圖的規則是根據each of which changes exactly one coordinate by 1這句話來的,,,,,,,,,,直接自閉。

首先建好圖,然後求最大獨立集就ok了,最大獨立集 = 點的個數 - 最大匹配數。

總結這道題被卡的原因:

對匈牙利演算法的理解太淺顯!

讀題不精!

代碼:

 

#include <bits/stdc++.h>#define inf 0x3f3f3f3fusing namespace std;typedef long 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++)//每個與u相連的點    {        int _v = v[u][i];//放進交替路中        if(!vis[_v])        {            vis[_v] = 1;            if(linker[_v]==0 || dfs(linker[_v]))//是未匹配點,說明該交替路是增廣路徑,交換路徑            {                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%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(最大獨立集)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.