题目:

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. POJ2115 C-Loop

    传送门 这道题是求解不定方程的一道好练习题. 题目描述的很诡异……还说什么k进制,其实就是要求一个数A,每次加C,问到B要加多少次,所有的数对2k取模. 也就是说我们能列出如下方程:A+xC ≡ B ...

  2. MySQL索引学习记录

    参考资料: http://blog.csdn.net/v_july_v/article/details/6530142http://blog.codinglabs.org/articles/theor ...

  3. 清北考前刷题day2早安

    /* 做法一:按h sort一遍,对于一段区间[i,j],高度花费就是h[j]-h[i] 然后枚举区间,把区间内C排序,一个一个尽量选即可. n^3logn 标算:n^3 dp 高度排序,保证从前往后 ...

  4. jQuery多项选择器

    jQuery多项选择器模式: $("selector1,selector2,selectorN"); 将每一个选择器匹配到的元素合并后一起返回,可以指定任意多个选择器,并将匹配到的 ...

  5. mysql 根据总分排名

    mysql 根据总分排名 SELECT t.*, @rank := @rank + AS rank FROM ( SELECT @rank := ) r, ( SELECT tas.id, tas.t ...

  6. activiti遇到的问题

    1.act_hi_detail表里面没有数据 原因是没有加历史变量的判断 2.流程图添加网关,写流转表达式 比如请假流程   大于3天小于5天的条件:${请假实体类.属性名称}

  7. deepin 安装版本管理工具

    在Linux下我们可以使用RapidSVN.RapidSVN是一款轻量级的免费.开源 SVN 客户端,相比tortoise svn它更加小巧而且占系统资源少运行速度快. 一:安装RapidSVN版本控 ...

  8. less新手入门(三) 作为函数使用的Mixin、@import 导入指令 、@import 导入选项

    五.作为函数使用的Mixin 从mixin返回变量 在mixin中定义的所有变量都是可见的,并且可以在调用者的作用范围中使用(除非调用者用相同的名称定义它自己的变量). .mixin(){ @widt ...

  9. [转]MVC之 自定义过滤器(Filter)

    本文转自:http://www.cnblogs.com/kissdodog/archive/2013/01/21/2869298.html 一.自定义Filter 自定义Filter需要继承Actio ...

  10. Asp 循环输出 form 表单提交的数据

    亲测asp提交form表单数据,在接收页面循环输出数据 dim var for each var in request.form response.write var&"=" ...