[二分匹配]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,暂时只 ...
随机推荐
- Micro Frontends & microservices
Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...
- import script module
import script module .mjs <script type="module"> import {addTextToBody} from './util ...
- nodejs stream 创建读写流
const fs = require("fs"); const { Writable, Readable, Duplex, Transform } = require(" ...
- Flutter Android Toast Message(flutter访问Android Toast Message)
原文 Android Toast通知可用于向用户发送快速消息,并在几秒钟后消失. 但是当涉及Flutter时,没有直接的方式来显示这些Toast消息.因此,我们需要找到一种替代方法来实现它.在这种情况 ...
- Tomcat 安装Manager
sudo apt-get install tomcat8-admin tomcat8-docs tomcat8-examplessudo vi /etc/tomcat8/tomcat-users.xm ...
- Linux graphics stack
2D图形架构 早期Linux图形系统的显示全部依赖X Server,X Client调用Xlib提供的借口向 X Server发送渲染命令,X Server根据 X Client的命令请求向硬件设备绘 ...
- xmake v2.5.2 发布, 支持自动拉取交叉工具链和依赖包集成
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- 清华大学-成绩排序(排序+解决MLE问题)
成绩排序 成绩排序 这里需要注意的就是超内存的问题. 解决方法就是通过指针的方式,每次动态开n大小的内存,而不是一开始就分配. #include<bits/stdc++.h> using ...
- Reincarnation Without New Body(RWNB): Basic Theory and Baseline 现世转生基本理论及简单操作
Abstract 投胎学是一门高深的学问,不仅没有现存的理论,也没有过往的经验.根据种种猜测,投胎后前世的记忆也不能保留,造成了很大的不方便.在本文中,我们绕过了投胎需要"来世"的 ...
- mysql 基本指令 1
desc 表名 --查看表属性 show create table 表名 \g; --查看代码 alter table 表名 auto_increment=20; --改自增的值 MySQL:自 ...