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
Prev Submit Status Statistics Discuss Next
Font Size:  
Type:  
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 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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小米3一直闪红灯怎么办 手机拨号键删了怎么办 联想笔记本电脑无线网卡坏了怎么办 联想z360内置无线网卡坏怎么办 usb无线网卡驱动安装失败怎么办 无线网被禁用了怎么办 未连接无线通信已关闭怎么办 手机设置路由器打不开了怎么办 手机打不开登录路由器的网址怎么办 按了光猫复位后怎么办 按了猫的复位键怎么办 望远镜的镜片小水雾是怎么办 坚果r1不断重启怎么办 忘记Wi-Fi密码了怎么办 魅蓝手机null锁住了怎么办 红米手机锁屏了怎么办 不记得锁屏密码怎么办 小米手机音量键坏了怎么办 小米6音量键坏了怎么办 小米2s开不开机怎么办 小米4不充电了怎么办 小米2开不开机怎么办 手机开机键开不了机怎么办 三星s4反复重启怎么办 小米5反复重启怎么办 电脑系统奔溃了怎么办 电脑开机后屏幕出现英文怎么办 小米4开不开机了怎么办 小米4一直显示mi怎么办 小米手机开关键失灵怎么办 小米手机开机键失灵怎么办 小米6不断重启怎么办 小米6一直重启怎么办 小米6自动重启怎么办 手机的开机键坏了怎么办 小米6频繁重启怎么办 小米6安装xp卡米怎么办 刷机失败反复重启怎么办 红米手机很卡怎么办啊 红米2a显示图标怎么办 手机一直处于开机状态怎么办