http://www.lydsy.com/JudgeOnline/problem.php?id=1693

裸匈牙利。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=505;
int ly[N+N], vis[N+N], ihead[N], cnt, n, m;
struct dat { int to, next; }e[10005];
void add(int u, int v) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v;
}
bool ifind(int x) {
int y;
for(int i=ihead[x]; i; i=e[i].next) if(!vis[y=e[i].to]) {
vis[y]=1;
if(!ly[y] || ifind(ly[y])) {
ly[y]=x;
return true;
}
}
return false;
} int main() {
read(n); read(m);
for1(i, 1, m) {
int u=getint(), v=getint();
add(u, v+n);
}
int ans=0;
for1(i, 1, n) {
CC(vis, 0);
if(ifind(i)) ++ans;
}
print(ans);
return 0;
}

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

INPUT DETAILS:

The following diagram represents the data, where "X" is an
asteroid and "." is empty space:
X.X
.X.
.X.

Sample Output

2

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

HINT

Source

最新文章

  1. vertical-align:middle
  2. ios block 导致的循环引用
  3. Unity3D DllNotFoundException/System.DllNotFoundException
  4. kafka使用
  5. 获取枚举Description 属性
  6. Tachyon框架的Worker心跳及Master高可用性分析
  7. linux脚本^M: bad interpreter:解决方法
  8. Django数据库配置
  9. mysql主从同步从库同步报错
  10. text选中后displa出label内容
  11. 使用pager进行分页
  12. 真正从零开始,TensorFlow详细安装入门图文教程!
  13. JAVA通过COM接口操作PPT
  14. Oracle WorkFlow(工作流)(二)
  15. UIAutomator简介
  16. Hadoop Mapreduce中shuffle 详解
  17. C++primer第一章(部分)
  18. iOS开发——无网占位图的实现
  19. 5-24 css内容的补充
  20. git submodule使用的笔记

热门文章

  1. Oracle Unicode转中文(解码)
  2. Python 小程序,对文件操作及其它
  3. jsp基本语法总结
  4. OFBiz:扩展controller.xml
  5. 增强基本选择器[selector_3.html]
  6. 【LeetCode】81. Search in Rotated Sorted Array II (2 solutions)
  7. [转载]最完整PHP.INI中文版
  8. Python -- 标准库 文件管理 (部分os包,shutil包)
  9. ASP.NET给DataGrid,Repeater等添加全选批量删除等功能
  10. 有道翻译 / 百度翻译Api