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 ...
随机推荐
- [转]全图形PPT设计指南
三.什么时候使用 全图形PPT并不适用于所有时候,一般来说,我们在以下场合可以考虑使用:陈述一个故事.名人简介.产品介绍.读书笔记.心灵鸡汤.生活情趣等. 四.如何制作全图形PPT 全图形PPT的制作 ...
- __bridge 使用注意
前奏 在平常开发中,我们可能遇到 CoreFoundation(CF) 框架的对象和 OC 对象之间的类型转换,这时候我们需要 __bridge 来帮忙 注意 : 如果是使用 CF __bridge ...
- leetcode 【 Linked List Cycle 】 python 实现
题目: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ...
- C++文件操作(转)
C++文件操作(转) 第一个:简单,容易理解,常用:http://www.cnblogs.com/uniqueliu/archive/2011/08/03/2126545.html 第二个:详细的,如 ...
- Java基础-3类和对象声明与创建
一).在1和2中有粗略介绍过类和对象的概念,在这里简单回顾一下: 对象与类:一个实际或者虚拟的物体,这个物体既是我们的对象,这个物体呢又是属于一个分类,如动物类,人类 二).创建对象: 在创建对象的时 ...
- CentOS7 编译安装nodejs,配置环境变量记录
每次都装,每次都查 阿里云备案了一个域名,续费了好多年,但是没钱买服务器,就挂在github上.今天收到消息:域名解析服务器不在阿里云,要被GG.只能咬牙买了个阿里云乞丐版. 所有服务都装好了,pin ...
- Python洗牌算法重写
Python有自带的洗牌算法函数shuffle(). 自己也通过学习也琢磨了一下它的实现,然后给出一个时间复杂度O(n),空间复杂度O(4)的例子: import random def shuffle ...
- 【linxu】部署docker容器虚拟化平台
实验所涉内容 Docker 概述 部署 docker 容器虚拟化平台 docker 平台基本使用方法 创建docker镜像和发布镜像方法 Container 容器端口映射 一 Docker 概述 Do ...
- 201621123034 《Java程序设计》第7周学习总结
作业07-Java GUI编程 1. 本周学习总结 1.1 思维导图:Java图形界面总结 1.2 可选:使用常规方法总结其他上课内容. 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模 ...
- asp.net 存储过程 输出参数 取不到值
这是MSDN上的明确解释:当您将 Command 对象用于存储过程时,可以将 Command 对象的 CommandType 属性设置为 StoredProcedure.当 CommandType 为 ...