BZOJ1693: [Usaco2007 Demo]Asteroids
来源:互联网 发布:电子实验室软件 编辑:程序博客网 时间:2024/06/16 11:22
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.
OutputLine 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
题目传送门
题意:一个矩阵地图N x N 个格子(1 <= N <= 500)。
有K个地雷藏在格子里(1 <= K <= 10,000)。
有一种大炮,一击就可以让在同一水平或垂直的地雷清除。
求最少击炮次数才可以清除所有地雷。
二分图最小覆盖模版
They say memories make us who we are,that the past defines us.But we can't forget to grow,evolve,because sometimes,a memory can be so powerful that we get stuck in it,frozen in a moment. 有人说是记忆成就了现在的我们,过去造就了我们,但是我们不能忘记去成长、去进步。因为有时记忆可以强大到让我们故步自封,沉睡在一瞬间。 ——《Forever》
代码如下:
#include<cstdio>#include<cstring>using namespace std;int match[11000];bool chw[11000];struct node{ int x,y,next;}a[210000];int len,last[410000];void ins(int x,int y){ len++; a[len].x=x;a[len].y=y; a[len].next=last[x];last[x]=len;}int n,m,k;bool findmuniu(int x){ for(int k=last[x];k;k=a[k].next) { int y=a[k].y; if(chw[y]==true) { chw[y]=false; if(match[y]==0||findmuniu(match[y])==true) { match[y]=x; return true; } } } return false;}int main(){ scanf("%d%d",&n,&m); len=0;memset(last,0,sizeof(last)); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); ins(x,y); } int ans=0; memset(match,0,sizeof(match)); for(int i=1;i<=n;i++) { memset(chw,true,sizeof(chw)); if(findmuniu(i)==true)ans++; } printf("%d\n",ans); return 0;}
by_lmy
- BZOJ1693: [Usaco2007 Demo]Asteroids
- BZOJ 1693 [Usaco2007 Demo]Asteroids 最大流
- BZOJ[1693][Usaco2007 Demo]Asteroids 网络流
- bzoj 1693: [Usaco2007 Demo]Asteroids(二分匹配)
- bzoj1629 [Usaco2007 Demo]Cow Acrobats
- bzoj1628 [Usaco2007 Demo]City skyline
- bzoj1630 [Usaco2007 Demo]Ant Counting
- 【BZOJ1628】【USACO2007 Demo】City Skyline
- 1628: [Usaco2007 Demo]City skyline
- [BZOJ1629][Usaco2007 Demo]Cow Acrobats
- bzoj1628【Usaco2007 Demo】City skyline
- bzoj1629[Usaco2007 Demo]Cow Acrobats
- 1629: [Usaco2007 Demo]Cow Acrobats
- [bzoj1629][Usaco2007 Demo]Cow Acrobats
- BZOJ 1628: [Usaco2007 Demo]City skyline
- BZOJ 1629: [Usaco2007 Demo]Cow Acrobats
- 【BZOJ 1629】 [Usaco2007 Demo]Cow Acrobats
- [BZOJ1628]=[BZOJ1683][Usaco2007 Demo]City skyline
- Java冒泡算法排序
- java中JFrame和Frame的窗体关闭区别
- MyBatis由浅入深学习总结之二:MyBatis解决Java实体类和数据库表字段不一致方法总结
- MyBatis由浅入深学习总结之二:MyBatis解决Java实体类和数据库表字段不一致方法总结
- Genymotion启动报错:the virtual device got no ip address
- BZOJ1693: [Usaco2007 Demo]Asteroids
- 动手实践:在Windows上安装NumPy、Matplotlib、SciPy
- 使用JavaMail的Java邮件发送
- 高阶函数与与匿名函数
- (Android集成支付宝支付)react-native实现支付宝支付
- 程序员,30岁,如何趁 AI 浪潮突破年薪天花板?
- Fragment切换 隐藏 显示
- 敏捷测试的“要”与“不要”-- 朱少民
- 软件设计管理工具 visual paradigm 社区版