N - 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.
Input
- 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.
Output
- Line 1: The integer representing the minimum number of times Bessie must shoot.
Sample Input
3 4
1 1
1 3
2 2
3 2
Sample Output
2
Hint
INPUT DETAILS:
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<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=505;
int pre[N];
int visit[N],line[N][N];
int n,m,y,x;
bool find(int x)
{
	rep(i,1,n+1)
	{
		if(line[x][i]&&visit[i]==0)
		{
			visit[i]=1;
			if(pre[i]==0||find(pre[i]))
			{
				pre[i]=x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	while(~sf("%d%d",&n,&m))
	{
		mm(line,0);
		mm(pre,0);
		while(m--)
		{
			sf("%d%d",&x,&y);
			line[x][y]=1;
		}
		int ans=0;
		rep(i,1,n+1)
		{
			mm(visit,0);
			if(find(i)) ans++;
		}
		pf("%d\n",ans);
	}
}
N - Asteroids的更多相关文章
- POJ 3041 Asteroids
		最小点覆盖数==最大匹配数 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12678 Accepted: ... 
- Asteroids(匈牙利算法入门)
		Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16211 Accepted: 8819 Descri ... 
- hdu 1240:Asteroids!(三维BFS搜索)
		Asteroids! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ... 
- POJ 3041 Asteroids(最小点覆盖集)
		Asteroids Time Limit: 1000MS Mem ... 
- Asteroids (最小覆盖)
		题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html Descriptio ... 
- poj 3041 Asteroids(最小点覆盖)
		http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ... 
- poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)
		http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions ... 
- HDU-1240    Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向
		Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ... 
- POJ 3041 Asteroids     最小点覆盖 == 二分图的最大匹配
		Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ... 
- Asteroids(二分图最大匹配模板题)
		Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12323 Accepted: 6716 Description Bess ... 
随机推荐
- 5、css补充
			css其余问题补充 本篇导航: 默认的高度和宽度问题 后台管理布局 css响应式布局 一.默认的高度和宽度问题 1.父子都是块级元素 <!DOCTYPE html> <html> ... 
- SpringCloud无废话入门03:Feign声明式服务调用
			1.Feign概述 在上一篇的HelloService这个类中,我们有这样一行代码: return restTemplate.getForObject("http://hello-servi ... 
- Android 使用easeui 3.0 集成环信即时通讯  我踩过的坑
			0.关于注冊账号就不用说了. 1.创建应用.获取appkey 0.创建应用 1.填写信息 2.获取appkey 2.集成 0.首先新建一个project 1.这里主要介绍使用easeui来集成环信的即 ... 
- boost::make_function_output_iterator报错: C4996
			用VS2013运行boost::make_function_output_iterator的官方例子: https://www.boost.org/doc/libs/1_68_0/libs/itera ... 
- BABLE 原理
			1.babel转换原理 2.主要过程 (1)babylon进行解析得到AST (2)babel-traverse插件对AST树进行遍历转译得到新的AST树 (3)babel-generator将AST ... 
- mysql字符串用法
			replace(str,from_str,to_str) --用字符串to_str替换字符串str中的子串from_str并返回 --mysql> select replace('www.mys ... 
- 用于Spring Boot Jar部署的shell脚本
			用于在Jenkins将jar发送到目标节点之后的部署操作, 包含deploy, start, stop, restart功能. 在deploy时会自动备份原jar至指定目录 # Please defi ... 
- systemctl  -- 系统服务管理器 【转】
			systemctl -- 系统服务管理器 systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 直接运行命令可以列出所有正在运行的服务 ... 
- IntelliJIdea 2016.2 使用 tomcat 8.5 调试spring的web项目时,bean被实例化两次导致timer和thread被启动了两遍的问题的解决
			今天新搭建了一个spring的web项目,项目启动时会启动一个线程,线程里定时执行任务,另外还启动了一个定时器,每秒钟统计系统吞吐量等业务性能数据.但是调试的时候惊奇的发现定时器和线程均被启动了两次. ... 
- Cordova 项目 加载不出XML文件
			解决方法:copy bundle 将文件移除再添加 
