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& ...
随机推荐
- python中 import 和from ... import 的区别
先看一个例子: 我自定义的一个moudle,里面有一个方法sayhi,还有一个变量version#!/usr/bin/env python # coding=utf-8 # Filename: mym ...
- vijos 1772 巧妙填数
描述 将1,2,\cdots,91,2,⋯,9共99个数分成三组,分别组成三个三位数,且使这三个三位数构成1:2:31:2:3的比例. 试求出所有满足条件的三个三位数.例如:三个三位数192,384, ...
- ftp 报错 200 Type set to A
最近在使用ssis 从ftp服务器抓起文件到本地的时候,发现连接ftp出错 200 Type set to A 解决办法: ftp connection 中 设置UsePassiveMode 为Tru ...
- 【算法】最长回文子串 longest palindrome substring
对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...
- How To Build Kubernetes Platform (构建Kubernetes平台方案参考)
Architecture Architecture Diagram Non-Prod Environment Prod Environment Cluster Networking Container ...
- (转)SpringMVC学习(八)——SpringMVC中的异常处理器
http://blog.csdn.net/yerenyuan_pku/article/details/72511891 SpringMVC在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常 ...
- PE基础1
PE文件概述 文件格式 .png ..mp4..gif..dll等等,这些文件都具有不同格式 不能随意修改这些文件,否则将无法打开 PE文件(可执行文件) 学习PE文件目标 掌握PE文件就掌握wino ...
- 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 ...
- C# 关于datetime的用法(网上考的)
实例: 用户输入一个日期,要求输出这个日期是星期几和在这一年中的第几天: 复制代码代码如下: //声明一个DateTime类型的变量用于存放用户输入的日期DateTime dt;Console.Wri ...
- poj 1664放苹果(转载,不详细,勿点)(递归)
题目和别人的解析传送门 我的代码 #include<bits/stdc++.h> using namespace std; int f(int m,int n) { ) ; ||m==) ...