A

s

t

e

r

o

i

d

s

Asteroids

Asteroids


题目描述

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.


输入

  • 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.

输出

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

样例输入

3 4
1 1
1 3
2 2
3 2

样例输出

2

题目解析

首先我们看题,是求一个最小的次数。
然后不会网络流的我只好用二分匹配
这道题其实和最大匹配 人员分配一模一样,就只是换了个题面而已。


code

#include<stdio.h>

#include<iostream> 

#include<string.h>

using namespace std;

int n, m, s, q, tot, ans;
int head[10005], link[1005], vis[1005]; struct node
{
int next,to;
}f[10005]; void add (int x, int y)
{
f[ ++ tot].next = head[x];
f[tot].to = y;
head[x] = tot;
} bool find (int x)
{
for (int i = head[x]; i; i = f[i].next)
{
int j = f[i].to;
if ( ! vis[j])
{
q = link[j];
link[j]=x;
vis[j]=1;
if ( ! q || find(q)) return 1;
link[j] = q;
} }
return 0; } int main ()
{
scanf ("%d%d", &m, &n);
for (int i=1; i<=n; ++i)
{
int a, b;
scanf("%d%d", &a, &b);
add (a,b);
}
for (int i=1; i<=n; ++i)
{
memset (vis, 0, sizeof(vis));
ans += find(i);
}
printf ("%d", ans);
return 0;
}

最新文章

  1. npm淘宝镜像cnpm
  2. 浏览器端获取局域网IP地址,本机的MAC,以及机器名
  3. 浅谈javascript函数节流
  4. EntityFramework+WCF
  5. htmL5 html5Validate
  6. Hadoop could not find or load main class
  7. Sublime Text 3 文本编辑器
  8. 功能测试中遇到的一些有意思的bug
  9. MySQL开启远程链接(2014.12.12)
  10. Eclipse插件基础篇一
  11. Python学习的个人笔记(基础语法)
  12. 获取当前 系统时间 + 获取当前URL 键值;
  13. Python二级-----------程序冲刺1
  14. 如何避免在IE内核时,按BackSpace时进行网页会进行回退
  15. jenkins使用总结
  16. linux:NFS
  17. 视角同步NewViewTarget
  18. C#对windows的IP网络测试(ping ip)
  19. 将Vue插件发布到npm的完整记录
  20. Timer Schedule参数说明

热门文章

  1. linux move file / folder bash command
  2. taro css 转换 bug
  3. 「NGK每日快讯」2021.1.8日NGK第66期官方快讯!
  4. 【Android初级】如何实现一个有动画效果的自定义下拉菜单
  5. es初步搭建
  6. Vue(1)
  7. 2021-2-26:为什么需要 System.gc() ?
  8. 前端问题录——在导入模块时使用&#39;@&#39;时提示&quot;Modile is not installed&quot;
  9. 查看手机CPU每个APP利用率
  10. vscode中js文件使用typescript语法报错,如何解决