[二分匹配]Asteroids
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的更多相关文章
- POJ-3041 Asteroids,二分匹配解决棋盘问题。
Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bessie wants to navigate her s ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
随机推荐
- flutter 1.5 in action
flutter 1.5 in action https://flutter.dev/docs/get-started/flutter-for/react-native-devs https://flu ...
- select notes mark
select notes mark mark-line https://time.geekbang.org/column/article/224545
- how to change sketch language to chinese
how to change sketch language to Chinese https://www.sketch.com/support/troubleshooting/chinese-loca ...
- parcel bug & not support normal import React & ReactDOM module
bug report not support normal import React & ReactDOM module, why Code Sample OK import * as Rea ...
- SVG & gradient & color
SVG & gradient & color https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Gradients & ...
- react 遍历 object
@observable obj = { name: "ajanuw", age: 22, }; @computed get list() { return _.toPairs(th ...
- 谁能成为数据储存领域领头羊?永久数据存储--NGK的终极使命!
区块链的目的是永远存储交易网络的历史.NGK技术团队能够永久存储其去中心化账本的副本.这是其日后能进行审计关键.一些著名的团队,如Solana和SKALE,现在正在为此与NGK进行最后的集成,我们预计 ...
- java基础第12期——反射、注解
一. 反射 反射: 将类的各个组成部分封装为其他对象. 1.1 获取class对象的方式 Class.forName("全类名"): 将字节码文件加载进内存,返回class对象 多 ...
- RxHttp - 轻量级、可扩展、易使用、完美兼容MVVM、MVC架构的网络封装类库
前言 RxHttp是基于RxJava2+Retrofit 2.9.0+OkHttp 4.9.0实现的轻量级,完美兼容MVVM架构的网络请求封装类库,小巧精致,简单易用,轻轻松松搞定网络请求. GitH ...
- DRF 三大认证的配置及使用方法
目录 三大认证 一.身份认证 1.身份认证配置 1.1 全局配置身份认证模块 1.2 局部配置身份认证模块 2.drf提供的身份认证类(了解) 3.rf-jwt提供的身份认证类(常用) 4.自定义身份 ...