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 ...
随机推荐
- 微信小程序中遮罩层的滚动穿透问题
如果弹出层没有滚动事件: <view wx:if="{{alert}}" catchtouchmove="myCatchTouch"> <te ...
- JIRA、Confluence中文官方技术博客
JIRA.Confluence中文官方技术博客 http://blog.csdn.net/atlassian2013
- centos下安装wireshark 抓包
centos下安装wireshark相当简单.两条命令就够了.这里.主要是记录写使用方面的东西 安装:1.yum install wireshark.注意这样并无法使用wireshark命令和图形界面 ...
- Unity中的定时器与延时器
JavaScript中的定时器与延时器,分别是 setInterval.setTimeout,对应的清理函数是:clearInterval.clearTimeout. 而在Unity中,则分别是:In ...
- Python的pandas
pandas 是python中很重要的组件,网上关于pandas 的文章也很多,比如Python科学计算之Pandas 和 Python数据分析入门 Pandas基于两种数据类型:series与dat ...
- PHP性能分析——xhprof(window 安装xhporf)
1 下载xhprof的php扩展 因为官方的xhprof不支持php7,所以采用tideways版本的xhprof 下载地址:windows版tideways_xhprof 将windows版的dll ...
- redis批量删除key 远程批量删除key
一.遇到的问题 在开发的过程中,经常会遇到要批量删除某种规则的key,如缓存的课程数据“course-课程uid”,其中课程uid是变量,我们需要删除"course-*"这一类的数 ...
- mysql时间日期操作
SELECT uid, SUBSTR(addtime,1,10) as 创建日期, endtime, TIMESTAMPDIFF(MINUTE, addtime, endtime) as 直播时长 f ...
- MySQL读取配置文件的顺序、启动方式、启动原理
一.MySQL读取配置文件的顺序 读取顺序:/etc/my.cnf > /etc/mysql/my.cnf > /usr/etc/my.cnf > ~/.my.cnf 命令验证:[r ...
- Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer 关于Newtonsoft.Json,LINQ to JSON的一个小demo mysql循环插入数据、生成随机数及CONCAT函数 .NET记录-获取外网IP以及判断该IP是属于网通还是电信 Guid的生成和数据修整(去除空格和小写字符)
Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer Advanced Installer :Free for 30 da ...