Gym - 101670J Punching Power(CTU Open Contest 2017 最大独立集)
题目:
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 最大独立集)的更多相关文章
- 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 ...
- Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)
题目&题意: 倒着找处于最后位置的等差数列的开头的位置. 例: 1 5 3 4 5 6 3 4 5 6是等差数列,它的开头的位置是3 PS: 读题真的很重要!!!!多组输入,上来就读错了!! ...
- Gym - 101670F Shooting Gallery(CTU Open Contest 2017 区间dp)
题目&题意:(有点难读...) 给出一个数字序列,找出一个区间,当删除这个区间中的两个相同的数字后,只保留这两个数字之间的序列,然后继续删除相同的数字,问最多可以实行多少次删除操作. 例如: ...
- Gym - 101670G Ice cream samples(CTU Open Contest 2017 尺取法)
题目: To encourage visitors active movement among the attractions, a circular path with ice cream stan ...
- Gym - 101670E Forest Picture (CTU Open Contest 2017 模拟)
题目: https://cn.vjudge.net/problem/1451310/origin 题意&思路: 纯粹模拟. 大体题意是这样的: 1.有人要在一个10-9<=x<=1 ...
- 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 ...
- Gym - 101670C Chessboard Dancing(CTU Open Contest 2017 找规律)
题目:链接 思路: 多画出几个情况就可以找出规律来了 Knight (当大于2的时候只要两种颜色相间出现就可以了) King(当大于等于3的时候,总可以用四种形式来补色,具体如下) Bishop(斜 ...
- 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 ...
- CTU Open Contest 2017
这场题很水.水题我就懒得贴了. B - Pond Cascade 优先队列维护这个水池需要多少时间 或者 直接扫一遍. #include <cstdio> #include <cst ...
随机推荐
- 【Codevs 2115】数集分割
http://codevs.cn/problem/2115/ // <2115.cpp> - Sun Oct 9 12:58:23 2016 // This file is made by ...
- Java IO流中 File文件对象与Properties类(四)
File类 用来将文件或目录封装成对象 方便对文件或目录信息进行处理 File对象可以作为参数传递给流进行操作 File类常用方法 创建 booleancreateNewFile():创建新文件,如果 ...
- Spark 决策树--分类模型
package Spark_MLlib import org.apache.spark.ml.Pipeline import org.apache.spark.ml.classification.{D ...
- Bug分支(转载)
转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178 ...
- bzoj 1638: [Usaco2007 Mar]Cow Traffic 奶牛交通【记忆化搜索】
震惊!记忆化搜索忘记返回map值调了半小时! 边(u,v)的经过次数是:能到u的牛数*v到n的方案数.正反两次连边,dfs两次即可 #include<iostream> #include& ...
- 清北考前刷题day4下午好
/* 辗转相除,每次计算多出现了几个数. */ #include<iostream> #include<cstdio> #include<cstring> #inc ...
- 【React Native】React Native项目设计与知识点分享
闲暇之余,写了一个React Native的demo,可以作为大家的入门学习参考. GitHub:https://github.com/xujianfu/ElmApp.git GitHub:https ...
- [Qt及Qt Quick开发实战精解] 第1章 多文档编辑器
这一章的例子是对<Qt Creator快速人门>基础应用篇各章节知识的综合应用, 也是一个规范的实例程序.之所以说其规范,是因为在这个程序中,我们对菜单什么时候可用/什么时候不可用.关 ...
- bash、dash(/bin/bash和/bin/sh)的区别
Linux中的shell有多种类型,其中最常用的几种是Bourne shell(sh).C shell(csh)和Korn shell(ksh).三种shell各有优缺点. Bourne ...
- Spark学习笔记1:Application,Driver,Job,Task,Stage理解
看了spark的原始论文和相关资料,对spark中的一些经常用到的术语做了一些梳理,记录下. 1,Application application(应用)其实就是用spark-submit提交的程序.比 ...