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. dark theme website

    dark theme website css var dark theme prefers-color-scheme https://developer.mozilla.org/en-US/docs/ ...

  2. js in depth & prototype & __proto__

    js in depth & prototype & proto 实例的 proto 与 父类的 prototype,同时指向 父类的构造函数: https://hackernoon.c ...

  3. NGK项目为什么要发币

    每个区块链创新应用的出现,基本都发行了自己的数字货币,像比特币,以太坊等.数字货币是区块链的资产,是区块链技术的一个应用,实现了用区块链传递价值的目的.目前市面上的数字货币林林总总几千种,其中公链发行 ...

  4. 聊聊CacheLine

    本文转载自聊聊CacheLine 导语 文章聊聊缓存一致性协议中我们提到过,缓存里面最小的单位是缓存行/缓存条目,但是缓存中的具体存储结构是什么样的,缓存行中有存放的是什么?在缓存中是如何寻找指定是还 ...

  5. JVM 字节码之 int 入栈指令

    本文转载自JVM 字节码之 int 入栈指令(iconst.bipush.sipush.ldc) 前言 本文介绍 int 入栈指令 iconst.bipush.sipubh.Idc. 当 int 取值 ...

  6. 【python】递归听了N次也没印象,读完这篇你就懂了

    听到递归总觉得挺高大上的,为什么呢?因为对其陌生,那么今天就来一文记住递归到底是个啥. 不过先别急,一起来看一个问题:求10的阶乘(10!). 求x的阶乘,其实就是从1开始依次乘到x.那么10的阶乘就 ...

  7. 关于MVCC,我之前写错了,这次我改好了!

    关于MVCC的原理,在<我想进大厂>之mysql夺命连环13问写过一次,但是当时写的其实并不准确,这个理解可以应付面试,帮助快速理解,但是他的真正实现原理我想再次拿出来说一说. 简单理解版 ...

  8. Python3.x 基础练习题100例(11-20)

    练习11: 题目: 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 分析: 兔子的规律为数列1,1,2, ...

  9. WPF窗口和用户控件事件相互触发

    问题1: WPF项目里有一个窗口和一个用户控件,窗口和用户控件里都有一个Button,点击窗口里的Button如何触发用户控件里Button的Click事件 解答: //窗口代码 public par ...

  10. Python爬虫学习笔记(四)

    Request: Test1(基本属性:POST): 代码1: import requests # 发送POST请求 data = { } response = requests.post(url, ...