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;
}

[二分匹配]Asteroids的更多相关文章

  1. POJ-3041 Asteroids,二分匹配解决棋盘问题。

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K       Description Bessie wants to navigate her s ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  4. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  5. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  6. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  7. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

随机推荐

  1. ESLint error level

    ESLint error level https://eslint.org/docs/user-guide/getting-started#configuration .eslintrc { &quo ...

  2. 教你玩转CSS 伪元素

    一.CSS 伪元素 CSS伪元素是用来添加一些选择器的特殊效果. 语法 伪元素的语法: selector:pseudo-element {property:value;} CSS类也可以使用伪元素: ...

  3. MySQL的简单使用方法备忘

    这只是一篇我的个人备忘录,写的是我常用的命令.具体可以参考"菜鸟教程" https://www.runoob.com/mysql/mysql-tutorial.html 登录(用户 ...

  4. Redis-第九章节-动态字符串

    目录 概述 SDS(动态字符串) SDS(动态字符串)与c语言字符串的区别 1.概述 String类型底层实现的简单动态字符串sds,是可以修改的字符串.它采用预分配冗余空间的方式来减少内存的频繁分配 ...

  5. 微信小程序中input标签高度设置

    如果没有设置高度所以显示的是控件自身的高度. 微信小程序input控件原始设置: 上图发现: 我只覆盖了官方input的height,而没有覆盖min-height; .query input{ bo ...

  6. 第39天学习打卡(UDP多线程在线咨询 URL)

    UDP多线程在线咨询  package com.kuang.chat; ​ import java.io.BufferedReader; import java.io.InputStreamReade ...

  7. python进阶(12)闭包

    闭包 首先了解一下:如果在一个函数的内部定义了另一个函数,外部的我们叫他外函数,内部的我们叫他内函数. 在一个外函数中定义了一个内函数,内函数里运用了外函数的临时变量,并且外函数的返回值是内函数的引用 ...

  8. python:虚拟环境与pip

    原生pip镜像下载速度较慢,配置使用国内镜像.这里选择清华镜像,文档地址:https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ pip 镜像配置 临时使用: ...

  9. PAT-1153(Decode Registration Card of PAT)+unordered_map的使用+vector的使用+sort条件排序的使用

    Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 ...

  10. OpenGL中的简单坐标系初看+VAO/VBO/EBO

    你好,三角形 一: 关于坐标的问题 标准化设备坐标:输入的顶点数据就应该在标准化设备坐标范围里面即:x,y,z的值都在(-1-1)之间.在这个区间之外的坐标都会被丢弃. 1.1一旦顶点数据传入顶点着色 ...