poj       3041——Asteroids
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22604   Accepted: 12247

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 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).

Source

题目大意
给你一个N*N的矩阵,有一些格子里有小行星,现在Bessie有一些威力很大的炮弹,每一次射击都能够消灭掉矩阵中一行或一列的小行星,
但是炮弹很贵,问你需要消灭掉所有小行星所需的最小炮弹数目。
思路:
这道题和上一道题的思路是一样的,我们只需要将每一行和每一列都当做是二分图的一个集合,然后在进行二分图匹配。
这道题就是一个裸的求最小点覆盖的题。在二分图中,最小点覆盖=最大匹配数。so,着我们就直接求最大匹配数就好了。
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 550
using namespace std;
bool vis[N];
int n,m,x,y,ans,pre[N],map[N][N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=n;i++)
     if(!vis[i]&&map[x][i])
     {
         vis[i]=true;
         if(!pre[i]||find(pre[i]))
         {
             pre[i]=x;
             ;
         }
     }
     ;
}
int main()
{
    n=read(),m=read();
    ;i<=m;i++)
     x=read(),y=read(),map[x][y]=;
    ;i<=n;i++)
     {
         memset(vis,,sizeof(vis));
         if(find(i)) ans++;
     }
    printf("%d",ans);
    ;
}



poj 3041——Asteroids的更多相关文章

  1. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)

    POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配) Description Bessie wants to navigate her spa ...

  2. POJ 3041 Asteroids (对偶性,二分图匹配)

    题目:POJ 3041 Asteroids http://poj.org/problem?id=3041 分析: 把位置下标看出一条边,这显然是一个二分图最小顶点覆盖的问题,Hungary就好. 挑战 ...

  3. 二分图最大匹配(匈牙利算法) POJ 3041 Asteroids

    题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http:// ...

  4. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  5. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  6. POJ 3041 Asteroids 二分图

    原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))

    题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...

  8. POJ 3041.Asteroids 最小顶点覆盖

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22905   Accepted: 12421 Descr ...

  9. POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1

    http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...

随机推荐

  1. python中 import 和from ... import 的区别

    先看一个例子: 我自定义的一个moudle,里面有一个方法sayhi,还有一个变量version#!/usr/bin/env python # coding=utf-8 # Filename: mym ...

  2. vijos 1772 巧妙填数

    描述 将1,2,\cdots,91,2,⋯,9共99个数分成三组,分别组成三个三位数,且使这三个三位数构成1:2:31:2:3的比例. 试求出所有满足条件的三个三位数.例如:三个三位数192,384, ...

  3. ftp 报错 200 Type set to A

    最近在使用ssis 从ftp服务器抓起文件到本地的时候,发现连接ftp出错 200 Type set to A 解决办法: ftp connection 中 设置UsePassiveMode 为Tru ...

  4. 【算法】最长回文子串 longest palindrome substring

    对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...

  5. How To Build Kubernetes Platform (构建Kubernetes平台方案参考)

    Architecture Architecture Diagram Non-Prod Environment Prod Environment Cluster Networking Container ...

  6. (转)SpringMVC学习(八)——SpringMVC中的异常处理器

    http://blog.csdn.net/yerenyuan_pku/article/details/72511891 SpringMVC在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常 ...

  7. PE基础1

    PE文件概述 文件格式 .png ..mp4..gif..dll等等,这些文件都具有不同格式 不能随意修改这些文件,否则将无法打开 PE文件(可执行文件) 学习PE文件目标 掌握PE文件就掌握wino ...

  8. Android N requires the IDE to be running with Java 1.8 or later

      Android Studio需要两个JDK: ide jdk和project jdk: 前者是IDE本身运行使用的JDK. 后者用于编译Java代码 Project JDK 可以通过file-&g ...

  9. C# 关于datetime的用法(网上考的)

    实例: 用户输入一个日期,要求输出这个日期是星期几和在这一年中的第几天: 复制代码代码如下: //声明一个DateTime类型的变量用于存放用户输入的日期DateTime dt;Console.Wri ...

  10. poj 1664放苹果(转载,不详细,勿点)(递归)

    题目和别人的解析传送门 我的代码 #include<bits/stdc++.h> using namespace std; int f(int m,int n) { ) ; ||m==) ...