题目:

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.

思路:

反向来解决这道题目,先对不符合条件的点建图,求这个图的二分匹配。

建图的规则是水平竖直相邻的,距离是1,不符合题意,其他的距离肯定是大于1.3米的,直接自闭。

首先建好图,然后求最大独立集就ok了,最大独立集 = 点的个数 - 最大匹配数。

总结这道题被卡的原因:

对匈牙利算法的理解太浅显!

读题不精!

代码:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = ;
struct Node
{
int x,y;
} node[maxn];
vector<int>v[maxn];
int n,vis[maxn],linker[maxn]; bool dfs(int u)
{
for(int i = ; i<v[u].size(); i++)//每个与u相连的点
{
int _v = v[u][i];//放进交替路中
if(!vis[_v])
{
vis[_v] = ;
if(linker[_v]== || dfs(linker[_v]))//是未匹配点,说明该交替路是增广路径,交换路径
{
linker[_v] = u;
linker[u] = _v;
return true;
}
}
}
return false;
} int match()
{
int res = ;
memset(linker,,sizeof(linker));
for(int i = ; i<n; i++)
{
memset(vis,,sizeof(vis));
if(linker[i]== && dfs(i))
res++;
}
return res;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i = ; i<=n; i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
}
for(int i = ; i<=n; i++)
{
v[i].clear();
for(int j = ; j<=n; j++)
{
if(abs(node[i].x-node[j].x)+abs(node[i].y-node[j].y)==)
{
v[i].push_back(j);
}
}
}
int ans = match();
//cout<<"ans: "<<ans<<endl;
printf("%d\n",n-ans);
}
return ;
}

Gym - 101670J Punching Power(CTU Open Contest 2017 最大独立集)的更多相关文章

  1. Gym - 101670H Go Northwest!(CTU Open Contest 2017 思维题+map)

    题目: Go Northwest! is a game usually played in the park main hall when occasional rainy weather disco ...

  2. Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)

    题目&题意: 倒着找处于最后位置的等差数列的开头的位置. 例: 1 5 3 4 5 6 3 4 5 6是等差数列,它的开头的位置是3 PS: 读题真的很重要!!!!多组输入,上来就读错了!! ...

  3. Gym - 101670F Shooting Gallery(CTU Open Contest 2017 区间dp)

    题目&题意:(有点难读...) 给出一个数字序列,找出一个区间,当删除这个区间中的两个相同的数字后,只保留这两个数字之间的序列,然后继续删除相同的数字,问最多可以实行多少次删除操作. 例如: ...

  4. Gym - 101670G Ice cream samples(CTU Open Contest 2017 尺取法)

    题目: To encourage visitors active movement among the attractions, a circular path with ice cream stan ...

  5. Gym - 101670E Forest Picture (CTU Open Contest 2017 模拟)

    题目: https://cn.vjudge.net/problem/1451310/origin 题意&思路: 纯粹模拟. 大体题意是这样的: 1.有人要在一个10-9<=x<=1 ...

  6. Gym - 101670H Dark Ride with Monsters(CTU Open Contest 2017 贪心)

    题目: A narrow gauge train drives the visitors through the sequence of chambers in the Dark Ride attra ...

  7. Gym - 101670C Chessboard Dancing(CTU Open Contest 2017 找规律)

    题目:链接 思路: 多画出几个情况就可以找出规律来了 Knight (当大于2的时候只要两种颜色相间出现就可以了) King(当大于等于3的时候,总可以用四种形式来补色,具体如下)  Bishop(斜 ...

  8. Gym - 101670B Pond Cascade(CTU Open Contest 2017 贪心,二分)

    题目: The cascade of water slides has been installed in the park recently and it has to be tested. The ...

  9. CTU Open Contest 2017

    这场题很水.水题我就懒得贴了. B - Pond Cascade 优先队列维护这个水池需要多少时间 或者 直接扫一遍. #include <cstdio> #include <cst ...

随机推荐

  1. Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格

    Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格 sudo add-apt-repository ppa:noobslab/macbuntu sudo a ...

  2. html5 canvas程序演示--P1197 [JSOI2008]星球大战

    html5 canvas程序演示--P1197 [JSOI2008]星球大战 <!doctype html> <html> <head> <meta char ...

  3. bzoj 2428 均分数据

    题目大意: 已知N个正整数 将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小 求最小均方差 思路: 模拟退火 #include<iostream> #include<c ...

  4. 4.7.6 Compaction of LR Parsing Tables

    4.7.6 Compaction of LR Parsing Tables A typical programming language grammar with 50 to 100 terminal ...

  5. 洛谷 P1084 疫情控制 —— 二分+码力

    题目:https://www.luogu.org/problemnew/show/P1084 5个月前曾经写过一次,某个上学日的深夜,精疲力竭后只有区区10分,从此没管... #include< ...

  6. 使用HttpClient MultipartEntityBuilder 上传文件,并解决中文文件名乱码问题

    遇到一种业务场景,前端上传的文件需要经过java服务转发至文件服务.期间遇到了原生HttpClient怎么使用的问题.怎么把MultipartFile怎么重新组装成Http请求发送出去的问题.文件中文 ...

  7. .gitignore(转载)

    转自:http://blog.csdn.net/liuqiaoyu080512/article/details/8648266 git 可以管理所有文件的变更, 但并不是所有文件都有意义. 大部分二进 ...

  8. MySQL基础 — 详细安装

    MySQL--安装 打开MySQL 5.5 安装文件开始: 点击Next 打上勾,再点击Next 点击Custom,说明如下: Typical(典型安装)        Installs the mo ...

  9. bzoj 1724: [Usaco2006 Nov]Fence Repair 切割木板【堆】

    如果反着看,看成合并木板,就和合并果子一样了,把若干块放进一个小根堆,然后每次取出两个合并,把合并结果加进答案和堆里 代码里小根堆用优先队列实现(懒 #include<iostream> ...

  10. P4196 [CQOI2006]凸多边形

    传送门 半平面交的讲解 然而这个代码真的是非常的迷--并不怎么看得懂-- //minamoto #include<bits/stdc++.h> #define fp(i,a,b) for( ...