[POJ3041]Asteroids】的更多相关文章

/** 题目:poj3041 Asteroids 链接:http://poj.org/problem?id=3041 题意:给定n*n的矩阵,'X'表示障碍物,'.'表示空格;你有一把枪,每一发子弹可以消除一行或者一列的障碍物, 问最少需要多少颗子弹可以清空障碍物? 思路:最小点集覆盖问题,等价于最大匹配.把所有的行看做二分图的左边的节点,所有的列看做二分图右边的节点. 如果f[i][j]==true;那么第i行与第j列有关系,连一条边.对这个二分图求最大匹配即可. 采用匈牙利算法. 匈牙利算法…
声明:本博客所有题解都参照了网络资料或其他博客,仅为博主想加深理解而写,如有疑问欢迎与博主讨论✧。٩(ˊᗜˋ)و✧*。 POJ3041 Asteroids 题目描述 假如你现在正处在一个 \(N*N\) 的矩阵中,这个矩阵里面有 \(K\) 个障碍物,你拥有一把武器,一发弹药一次能消灭一行或一列的障碍物,求最小的弹药消灭全部障碍物 Solution 这是经典的最小点覆盖问题,用到了二分图匹配的思想 建图方式:我们把行和列分成左右两组,对于每个障碍物 \((x, y)\) 进行连边 只要每个障碍物…
原文链接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…
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…
题目链接. 分析: 暂略. AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> #include <algorithm> #include <cmath> #include <string> #include <map> using namespace s…
嘟嘟嘟 虽然我已经会网络流了,但是还是学了一个匈牙利算法. --就跟我会线段树,但还是学了树状数组一样. 其实匈牙利算法挺暴力的.简单来说就是先贪心匹配,然后如果左部点\(i\)匹配不上了,就尝试更改前面已经匹配好的点,腾出地给他匹配. 因此对于每一个点跑一遍匈牙利算法,如果这个点匹配成功,总匹配数就加1. 感觉没啥好讲的. 关于这道题怎么做,看我这篇博客吧. #include<cstdio> #include<iostream> #include<cmath> #in…
题目大意:$N*N$的网格中有$n$颗行星,若每次可以消去一整行或一整列,求最小的攻击次数使得消去所有行星. 解题关键:将光束当做顶点,行星当做连接光束的边建图,题目转化为求该图的最小顶点覆盖,图的最小顶点覆盖是$NP$问题,又因为该图是二分图(水平方向的点和竖直方向的点),而二分图的最大匹配=最小顶点覆盖,即可求解该问题. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdli…
传送门 题意: 给一个N*N的矩阵,有些格子有障碍,要求我们消除这些障碍,问每次消除一行或一列的障碍,最少要几次.   解析: 把每一行与每一列当做二分图两边的点. 某格子有障碍,则对应行与列连边. 选出最少的点,使得所有边被覆盖. 最小点覆盖. ——代码 #include <cstdio> #include <cstring> #define M(x, a) memset(a, x, sizeof(a)) using namespace std; ; int n, k, cnt,…
最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman-ford,spfa) poj1511 - Invitation Cards(单源来回最短路径,spfa邻接表) poj1797 - Heavy Transportation(最大边,最短路变形,dijkstra,spfa,bellman-ford) poj2240 - Arbitrage(汇率问题,…
http://poj.org/problem?id=3041 题目大意:激光可以干掉一整行或一整列陨石,求最少激光次数. —————————————————— 二分图匹配,对于每一个陨石将它的横纵坐标相连. 然后发现我们需要将每一条边中的端点之一都覆盖掉,就是最小点覆盖. 有结论最小点覆盖=最大匹配数. 然后本题就切了. #include <cstdio> #include <iostream> #include <cmath> #include <cstring…
二分图的最大匹配=最小顶点覆盖(Konig定理)=最大独立集的补集最大匹配经典的三种模型  这题就是最小顶点覆盖,顺便这题留给我的经验就是调试的时候一定要细心细心再细心对模板的各个细节都要熟!! #include<cstdio> #include<string.h> #include<iostream> using namespace std; const int maxn=10005; intn,map[maxn][maxn]={{0}},match[maxn]={0…
POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) 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), whic…
   Asteroids POJ - 3041 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 po…
 最小点覆盖数==最大匹配数 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12678 Accepted: 6904 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 co…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16211   Accepted: 8819 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 as…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17237   td>Accepted: 9375 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 contain…
Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3159    Accepted Submission(s): 2106 Problem Description You're in space.You want to get home.There are asteroids.You don't want to hit…
                                                                  Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20748   Accepted: 11278 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in…
题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html 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 astero…
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17543   Accepted: 9548 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12162   Accepted: 6620 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 as…
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12601   Accepted: 6849 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <…
二分匹配的灵活运用 3041还是比较好想的,考虑到横排/竖排射一枪就能搞定这一行/一列的所有点, 我们以行数为点集x,列数为点集y,在目标点(xi,yi)之间连一条边 这样最小射击次数=最小点覆盖(边两端点至少有一个点在覆盖集中)=最大匹配 poj2226是它的加强版 这里一块木板不能覆盖非泥泞点,也就是说一块木板不一定能搞定那一行所有的点 于是我们考虑到将连续的泥泞点标号,表示这些泥泞点是由哪个木板盖住(横竖分别标号) 这样,我们以横排木板为点集x,竖排木板为点集y,对于每个点,在盖住它的横竖…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2664    Accepted Submission(s): 1794 Problem Description You're in space. You want to get home. There are asteroids. You don't want to hit them.…
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…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12323   Accepted: 6716 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…
Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2599    Accepted Submission(s): 1745 Problem Description You're in space. You want to get home. There are asteroids. You don't want to…