poj 3041——Asteroids
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 22604 | Accepted: 12247 |
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).
Source
#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的更多相关文章
- 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 http://poj.org/problem?id=3041 分析: 把位置下标看出一条边,这显然是一个二分图最小顶点覆盖的问题,Hungary就好. 挑战 ...
- 二分图最大匹配(匈牙利算法) POJ 3041 Asteroids
题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http:// ...
- 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 ...
- POJ 3041 Asteroids 二分图
原题连接:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))
题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...
- POJ 3041.Asteroids 最小顶点覆盖
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22905 Accepted: 12421 Descr ...
- POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1
http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...
随机推荐
- codevs 2761 脏话过滤
时间限制: 1 s 空间限制: 8000 KB 题目等级 : 白银 Silver 题目描述 Description 某论坛希望打造文明论坛,对于每个帖子需要将脏话换成*输出. 脏话有38,25 ...
- 使用Eclipse进行PHP的服务器端调试
最近工作需要对PHP的服务器端代码进行远程调试,涉及到Eclipse里环境的设置.在网上找了很多资料,大多不全,或者缺少配图,于是把自己做的过程中遇到的问题记录了下来,希望对需要的朋友们有所帮助. 首 ...
- VBA Promming——入门教程
VBA Visual Basic for Applications(VBA)是Visual Basic的一种宏语言,是微软开发出来在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言.主要能用来 ...
- 网新恩普(W 笔试)
选择题 1.一桶有黄色,绿色,红色三种,闭上眼睛抓取同种颜色的两个.抓取多少个就可以确定你肯定有两个同一颜色的球? 答案: 4次 1.最坏打算抓3次都是不同颜色的黄.绿.红,此时,三种颜色的球各抓了一 ...
- uva1627 Team them up!
注意这题要求互相认识不认识的人之间连一条线一个人在组1,那么不认识(互相认识)的人就在组0:同时这些人不认识的人就在组1.每个联通分量都可以独立推导,遇到矛盾则无解一个联通分量有一个核心,其他的点是分 ...
- navicat 链接数据库查看的工具 可以同时查看各种数据库 MySql SqlServer
navicat 链接数据库查看的工具 Navicat_Premium_10.0.11.0_XiaZaiBa
- 清空表单方法 清空变量 iview modal
方法一 通过json序列号和反序列号 清空一次数据 数据需要copy出来一份 orgFormClearAllInput () { this.$refs.n1.formValidate = JSON.p ...
- QT_3
1.QT中命名的规范和常用的快捷键 1.1 命名规范: 类名:首字母大写 多个单词时单词与单词之间首 字母大写 函数名:变量名称 首字母小写 多个单词时,单词和单词之间首字母大写 1. ...
- mean shift博客推荐
https://blog.csdn.net/maweifei/article/details/78766784 https://blog.csdn.net/gdfsg/article/details/ ...
- Vickers Vane Pump - How To Choose Vane Pump Parameter Specifications?
1 rated pressure selection. The rated pressure of the vane pump products is 7MPa, 1OMPa, 16MPa, 2lMP ...