POJ 3041.Asteroids-Hungary(匈牙利算法)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 23963 | Accepted: 12989 |
Description
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.
Input
* 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.
Output
Sample Input
3 4
1 1
1 3
2 2
3 2
Sample Output
2
Hint
The following diagram represents the data, where "X" is an asteroid and "." is empty space:
X.X
.X.
.X.
OUTPUT DETAILS:
Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <ctime>
#include <vector>
using namespace std;
const int maxn= ;
const int maxm=+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n,m;
int match[maxm];
bool visited[maxm];
bool mp[maxm][maxm];
bool Find(int x){
for(int i=;i<=n;i++){
if(mp[x][i]&&visited[i]==){
visited[i]=true;
if(match[i]==||Find(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
int main(){
int x,y,num;
while(~scanf("%d%d",&n,&m)){
memset(mp,,sizeof(mp));
memset(match,,sizeof(match));
memset(visited,,sizeof(visited));
for(int i=;i<m;i++){
scanf("%d%d",&x,&y);
mp[x][y]=true;
}
num=;
for(int i=;i<=n;i++){
memset(visited,,sizeof(visited));
if(Find(i))num++;
}
printf("%d\n",num);
}
return ;
}
溜啦溜啦,去写多校的二分图的题啦。
POJ 3041.Asteroids-Hungary(匈牙利算法)的更多相关文章
- POJ 3041 Asteroids(匈牙利+邻接表)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cstring> #include<algo ...
- 二分图最大匹配(匈牙利算法) POJ 3041 Asteroids
题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http:// ...
- POJ 3041 Asteroids (对偶性,二分图匹配)
题目:POJ 3041 Asteroids http://poj.org/problem?id=3041 分析: 把位置下标看出一条边,这显然是一个二分图最小顶点覆盖的问题,Hungary就好. 挑战 ...
- POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)
POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...
- poj 3041——Asteroids
poj 3041——Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22604 Accep ...
- poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)
http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利 ...
- POJ 3041 Asteroids(二分图 && 匈牙利算法 && 最小点覆盖)
嗯... 题目链接:http://poj.org/problem?id=3041 这道题的思想比较奇特: 把x坐标.y坐标分别看成是二分图两边的点,如果(x,y)上有行星,则将(x,y)之间连一条边, ...
- poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)
http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))
题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...
- POJ:3041-Asteroids(匈牙利算法模板)
传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bes ...
随机推荐
- 每天一个Linux命令(10):mv命令
mv命令用来对文件或目录重新命名,或者将文件从一个目录移到另一个目录中.source表示源文件或目录,target表示目标文件或目录.如果将一个文件移到一个已经存在的目标文件中,则目标文件的内容将被覆 ...
- appium 多个设备同时执行
测试需要同时在多个android设备上运行,就需要启动多个appium 使用adb命令获取udid,命令:adb get-serialno 使用的是testng测试框架,代码使用java编写 第一台, ...
- Python利器一之requests
Python利器一之requests 一.教程涉及开发语言.脚本.框架.数据库等内容 Python + requests 通过 pip 安装: pip install requests 通过 easy ...
- Jforum环境搭建
前提:搭建好JDK.JRE.Tomcat.数据库 1.之前安装了Navicat Premium,所以直接用这个创建名为jforum的MySQL数据库,默认密码为空,记得设置密码,因为Jforum要用到 ...
- Python全栈工程师(递归函数、闭包)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 全栈工程师 Python人工智能从入门到精通 函数式编程: 是指用一系列函数解决问题 每一个函数完成细 ...
- CodeForces-1061B Views Matter
题目链接 https://vjudge.net/problem/CodeForces-1061B 题面 Description You came to the exhibition and one e ...
- 贪吃蛇StringBuilder 和 定时器
ConsoleKeyInfo info = Console.ReadKey(); while (true) { if (info.Key == ConsoleKey.UpArrow)//只能输入一次但 ...
- Linux 内核数据结构bitmap
#include <stdio.h> #include <stdlib.h> #define MAX_PRIO 10000 #define BITS_PER_LONG 32 # ...
- [xsy1129] flow [树链剖分和线段树一起优化网络流][我也不知道这是什么鬼标签]
题面 内部OJ 思路 考虑一个决策方案${x}$,$x_i$表示第$i$个点选不选,$f^k_i$表示点$i$的第$k$个父亲 那么可以得到总花费的表达式$ans=\sum V_i x_i - \su ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...