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

【BZOJ】1693: [Usaco2007 Demo]Asteroids(匈牙利)的更多相关文章

  1. BZOJ1693: [Usaco2007 Demo]Asteroids

    n<=500 *n的格子,给m<=10000个格子有人,一炮可以清掉一行或一列的人(莫名的爽!)求最少几炮干掉所有人. 经典二分图模型!行成点,列成点,一个点就连接一行一列,表示这一行或这 ...

  2. BZOJ 1695 [Usaco2007 Demo]Walk the Talk 链表+数学

    题意:链接 方法:乱搞 解析: 出这道题的人存心报复社会. 首先这个单词表-先上网上找这个单词表- 反正总共2265个单词.然后就考虑怎么做即可了. 刚開始我没看表,找不到怎么做,最快的方法我也仅仅是 ...

  3. BZOJ 1629: [Usaco2007 Demo]Cow Acrobats

    Description Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away a ...

  4. BZOJ 1628 [Usaco2007 Demo]City skyline:单调栈

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1628 题意: 题解: 单调栈. 单调性: 栈内元素高度递增. 一旦出现比栈顶小的元素,则表 ...

  5. bzoj 1630: [Usaco2007 Demo]Ant Counting【dp】

    满脑子组合数学,根本没想到dp 设f[i][j]为前i只蚂蚁,选出j只的方案数,初始状态为f[0][0]=1 转移为 \[ f[i][j]=\sum_{k=0}^{a[i]}f[i-1][j-k] \ ...

  6. bzoj 1628: [Usaco2007 Demo]City skyline【贪心+单调栈】

    还以为是dp呢 首先默认答案是n 对于一个影子,如果前边的影子比它高则可以归进前面的影子,高处的一段单算: 和他一样高的话就不用单算了,ans--: 否则入栈 #include<iostream ...

  7. bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】

    仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...

  8. BZOJ1629: [Usaco2007 Demo]Cow Acrobats

    1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 601  Solved: 305[Su ...

  9. BZOJ1628: [Usaco2007 Demo]City skyline

    1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Su ...

随机推荐

  1. IOS手机使用Fiddler抓获HTTPS报文方法

    Configure Fiddler Click Tools > Fiddler Options > Connections. Click the checkbox by Allow rem ...

  2. 利用端口映射解决:拥有公网IP有限,内网需要访问因特网

    动态端口映射:   内网中的一台电脑要访问新浪网,会向NAT网关发送数据包,包头中包括对方(就是新浪网)IP.端口和本机IP.端口,NAT网关会把本机IP.端口替换成自己的公网IP.一个未使用的端口, ...

  3. 注意Hibernate4在开发当中的一些改变

    Hibernate4的改动较大只有spring3.1以上版本能够支持,Spring3.1取消了HibernateTemplate,因为Hibernate4的事务管理已经很好了,不用Spring再扩展了 ...

  4. 用PL/pgSQL写postgreSQL的存储过程[转]

    http://blog.chinaunix.net/uid-7591044-id-1742967.html 今天学会了用 PL/pgSQL 写 postgreSQL 的存储过程,网上资料实在少得可怜, ...

  5. 工作总结 Rezor 里面的一些小知识----自定义类型 放在标签值中 会直接跳过去

    0 的时候不报错 1 的时候 报错了 原因 是 imagesname[i]  索引超出了 为什么在 上面 报错呢?  不在这里报错呢? 说明了  Rezor 对于 自定义的变量 放在标签值里的时候,调 ...

  6. firefox浏览器批处理插件imacros

    http://www.360doc.com/content/14/1012/19/4360822_416372016.shtml javascript部分 var code = "CODE: ...

  7. unity, do nothing的state

    要想在animator的stateMachine中建一个"doNothing",要注意:为了保证"doNothing"state能正常运转,不被无故跳过, Mo ...

  8. 167. Add Two Numbers【easy】

    You have two numbers represented by a linked list, where each node contains a single digit. The digi ...

  9. zookeeper单节点windows下安装

    由于需要在windows下面安装zookeeper,故做个整理 1.下载zookeeper http://mirrors.hust.edu.cn/apache/zookeeper/ 2.解压 3.修改 ...

  10. makefile之override

    override指示符 通常在执行 make 时,如果通过命令行定义了一个变量,那么它将替代在 Makefile中出现的同名变量的定义. 就是说,对于一个在 Makefile 中使用常规方式(使用&q ...