Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.

Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.

Input

  • Line 1: Two integers N and K, separated by a single space.
  • Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.

Output

  • Line 1: The integer representing the minimum number of times Bessie must shoot.

Sample Input

3 4

1 1

1 3

2 2

3 2

Sample Output

2

Hint

INPUT DETAILS:

The following diagram represents the data, where "X" is an asteroid and "." is empty space:

X.X

.X.

.X.

OUTPUT DETAILS:

Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).

求发射多少次能将行星都摧毁,把坐标的横纵坐标可以当做是两个点集合,然后糗事求最小点覆盖,用匈牙利算法

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=505;
int pre[N];
int visit[N],line[N][N];
int n,m,y,x;
bool find(int x)
{
rep(i,1,n+1)
{
if(line[x][i]&&visit[i]==0)
{
visit[i]=1;
if(pre[i]==0||find(pre[i]))
{
pre[i]=x;
return true;
}
}
}
return false;
}
int main()
{
while(~sf("%d%d",&n,&m))
{
mm(line,0);
mm(pre,0);
while(m--)
{
sf("%d%d",&x,&y);
line[x][y]=1;
}
int ans=0;
rep(i,1,n+1)
{
mm(visit,0);
if(find(i)) ans++;
} pf("%d\n",ans);
}
}

N - Asteroids的更多相关文章

  1. POJ 3041 Asteroids

     最小点覆盖数==最大匹配数 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12678 Accepted:  ...

  2. Asteroids(匈牙利算法入门)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16211   Accepted: 8819 Descri ...

  3. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. POJ 3041 Asteroids(最小点覆盖集)

                                                                      Asteroids Time Limit: 1000MS   Mem ...

  5. Asteroids (最小覆盖)

    题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html Descriptio ...

  6. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  8. HDU-1240 Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...

  9. POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

  10. Asteroids(二分图最大匹配模板题)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12323   Accepted: 6716 Description Bess ...

随机推荐

  1. js扩展运算符(spread)三个点(...)

    常见用法: 1.该运算符主要用于函数调用. function push(array, ...items) { array.push(...items); } function add(x, y) { ...

  2. IntelliJ IDEA 下载安装(含注册码)

    https://blog.csdn.net/mashuai720/article/details/79389314

  3. 您的第一个C++Builder程序(Hello, world!)

    最近有些老旧的项目是C++Builder开发的,虽然和Delphi的IDE的界面和操作十分相似,但是还是找本<C++ Builder 5 Developer's Guide>来看看熟悉下, ...

  4. elasticsearch外网访问设置

    默认情况下安装elasticsearch之后是无法进行外网访问的,可以通过设置来完成这一目的 1.更改配置文件 [***@elk01 ~]$ vim elk/config/elasticsearch. ...

  5. 动态绑定事件到特定dom元素上,包含新增加的

    $('body').on('click', 'a.detail-data', function (e) { //动态事件绑定 为body元素下所有的a.detail-data元素添加一个事件 包括新增 ...

  6. 20.2.翻译系列:EF 6中基于代码的数据库迁移技术【EF 6 Code-First系列】

    原文链接:https://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx EF 6 ...

  7. maven仓库中心mirrors配置多个下载中心(执行最快的镜像)

    E:\Program FilesApache Software Foundationapache-maven-3.5.4-binconf\settings.xmlmaven仓库中心mirrors配置多 ...

  8. SNF快速开发平台2019-APP移动端实际应用效果

    废话不多说,直接上效果图: 这是我们移动端框架基本程序+组件库+标准业务程序,当然了还需要配合上我们的代码生成器则更如虎添翼.https://www.cnblogs.com/spring_wang/p ...

  9. 使用ansible结合FTP部署zabbix_agent

    想要达到的效果:一条命令,快速对多台主机部署zabbix_agent 实现思路:从源码编译编译出zabbix_agentd,准备好安装脚本,将安装脚本和编译出的agent一起上传到FTP服务器,在an ...

  10. Why does deep learning work?

    Learning Deep Architectures for AI By Yoshua Bengio http://www.iro.umontreal.ca/~bengioy/papers/ftml ...