POJ3041:Asteroids——题解】的更多相关文章

声明:本博客所有题解都参照了网络资料或其他博客,仅为博主想加深理解而写,如有疑问欢迎与博主讨论✧。٩(ˊᗜˋ)و✧*。 POJ3041 Asteroids 题目描述 假如你现在正处在一个 \(N*N\) 的矩阵中,这个矩阵里面有 \(K\) 个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭全部障碍物 Solution 这是经典的最小点覆盖问题,用到了二分图匹配的思想 建图方式:我们把行和列分成左右两组,对于每个障碍物 \((x, y)\) 进行连边 只要每个障碍物…
/** 题目:poj3041 Asteroids 链接:http://poj.org/problem?id=3041 题意:给定n*n的矩阵,'X'表示障碍物,'.'表示空格;你有一把枪,每一发子弹可以消除一行或者一列的障碍物, 问最少需要多少颗子弹可以清空障碍物? 思路:最小点集覆盖问题,等价于最大匹配.把所有的行看做二分图的左边的节点,所有的列看做二分图右边的节点. 如果f[i][j]==true;那么第i行与第j列有关系,连一条边.对这个二分图求最大匹配即可. 采用匈牙利算法. 匈牙利算法…
http://poj.org/problem?id=3041 题目大意:激光可以干掉一整行或一整列陨石,求最少激光次数. —————————————————— 二分图匹配,对于每一个陨石将它的横纵坐标相连. 然后发现我们需要将每一条边中的端点之一都覆盖掉,就是最小点覆盖. 有结论最小点覆盖=最大匹配数. 然后本题就切了. #include <cstdio> #include <iostream> #include <cmath> #include <cstring…
原文链接http://www.cnblogs.com/zhouzhendong/p/8229200.html 题目传送门 - POJ3041 题意概括 有一个n*n的矩阵,有些点是障碍物. 现在每次可以炸掉某一行或者某一列的障碍物,问最少炸几次. 题解 对于点(x,y),我们建立一条x<->y+n的边,然后发现这是一个二分图. 我们只需要求最小点覆盖就可以了,因为最小点覆盖=最大匹配,所以匈牙利一波即可. 代码 #include <cstring> #include <cst…
Asteroids 好久没打过网络流相关的题了...... 题意:一个矩阵n×n,有m个东西,一次去掉一整行或一整列,问最少次数. 题解:匈牙利. 把每行变成一个点(X集合),每列变成一个点(Y集合),每个东西(x,y)连接Xx,Yy,最大匹配即为答案. 证明:对于一行(或一列)的东西,它们都是二分图里的一条边,所以如果这一行有匹配,答案会加1,且这些东西都会被这一行"吞"掉,不会再计入答案. 代码: // It is made by XZZ #include<cstdio>…
Description 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…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20686   Accepted: 11239 Description 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 a…
Description 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…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K       Description 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), wh…
Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6174    Accepted Submission(s): 3876 Problem Description You're in space.You want to get home.There are asteroids.You don't want to hit…