BOJ 3160 Asteroids //二分图水题
来源:互联网 发布:幼儿绘画软件 编辑:程序博客网 时间:2024/06/06 18:16
Asteroids
1000ms
65536KB
This problem will be judged on PKU. Original ID: 3041
64-bit integer IO format: %lld Java class name: Main
64-bit integer IO format: %lld Java class name: Main
Font Size:
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.
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.
* 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 41 11 32 23 2
Sample Output
2
Source
USACO 2005 November Gold
#include <stdio.h>#include <string.h>#define p 505bool tu[p][p];bool visit[p];int r[p];bool dfs(int a, int n){int i;for(i=1; i<=n; i++){if(tu[a][i] && !visit[i]){visit[i] = true;if(r[i]==-1 || dfs(r[i], n)){r[i] = a;return true;}}}return false;}int main(){int n;int i, k, x, y;int ans;while(scanf("%d%d", &n, &k)!=-1){ans = 0;memset(tu, false, sizeof(tu));for(i=1; i<=n; i++){r[i] = -1;}for(i=0; i<k; i++){scanf("%d%d", &x, &y);tu[x][y] = true;}for(i=1; i<=n; i++){memset(visit, false, sizeof(visit));if( dfs(i, n) )ans++;}printf("%d\n", ans);}return 0;}
0 0
- BOJ 3160 Asteroids //二分图水题
- BOJ 5291 Girls and Boys //二分图水题
- 二分 Asteroids
- POJ3041 Asteroids(二分图)
- Asteroids--二分图
- Asteroids 二分图
- Asteroids(二分图匹配)
- Asteroids (二分图)
- POJ3041 Asteroids【二分匹配】
- Poj3041-Asteroids-【二分图】
- 【Asteroids】二分图
- [二分图]Asteroids
- POJ 3041 Asteroids 二分匹配
- poj3041--Asteroids(二分匹配)
- 【POJ】3041 Asteroids 二分匹配
- Asteroids+POJ+二分图匹配
- poj 3041 Asteroids 二分图
- 【POJ 3041 Asteroids】+ 二分图
- 如何取消文件的默认打开方式
- 华为编程大——字符串匹配
- TOJ 1401. All in All
- python基础
- HDU 1114---Piggy-Bank【一维完全背包】
- BOJ 3160 Asteroids //二分图水题
- Struts2学习笔记(四) Action(中)
- python模块
- linux实现新的系统调用
- filenamefilter 过滤器的使用
- uva 11212 - Editing a Book(迭代加深搜索 IDA*) 迭代加深搜索
- Android一个布局文件嵌套另一个布局文件的方法
- 个人炒汇一定要坚持的交易原则
- 字符串--BF和KMP算法