BZOJ1693: [Usaco2007 Demo]Asteroids
n<=500 *n的格子,给m<=10000个格子有人,一炮可以清掉一行或一列的人(莫名的爽!)求最少几炮干掉所有人。
经典二分图模型!行成点,列成点,一个点就连接一行一列,表示这一行或这一列必选其一!
不喜欢匈牙利!跑网络流!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std; int n,m;
#define maxn 1011
#define maxm 22011
struct Edge{int to,next,cap,flow;};
const int inf=0x3f3f3f3f;
struct Network
{
Edge edge[maxm];int first[maxn],le,n,s,t;
void clear(int n)
{
memset(first,,sizeof(first));
le=;this->n=n;
}
void in(int x,int y,int cap)
{
Edge &e=edge[le];
e.to=y;e.cap=cap;e.flow=;
e.next=first[x];first[x]=le++;
}
void insert(int x,int y,int cap) {in(x,y,cap);in(y,x,);}
int dis[maxn],cur[maxn],que[maxn],head,tail;
bool bfs()
{
memset(dis,,sizeof(dis));
dis[s]=;
que[head=(tail=)-]=s;
while (head!=tail)
{
const int now=que[head++];
for (int i=first[now];i;i=edge[i].next)
{
Edge &e=edge[i];
if (e.cap>e.flow && !dis[e.to])
{
dis[e.to]=dis[now]+;
que[tail++]=e.to;
}
}
}
return dis[t];
}
int dfs(int x,int a)
{
if (x==t || !a) return a;
int flow=,f;
for (int &i=cur[x];i;i=edge[i].next)
{
Edge &e=edge[i];
if (dis[e.to]==dis[x]+ && (f=dfs(e.to,min(a,e.cap-e.flow)))>)
{
e.flow+=f;
edge[i^].flow-=f;
a-=f;
flow+=f;
if (!a) break;
}
}
return flow;
}
int Dinic(int s,int t)
{
this->s=s,this->t=t;
int ans=;
while (bfs())
{
for (int i=;i<=n;i++) cur[i]=first[i];
ans+=dfs(s,inf);
}
return ans;
}
}g;
int x,y;
int main()
{
scanf("%d%d",&n,&m);
g.clear(n*+);
int s=g.n-,t=g.n;
for (int i=;i<=n;i++) g.insert(s,i,);
for (int i=n+;i<=n*;i++) g.insert(i,t,);
for (int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
g.insert(x,y+n,);
}
printf("%d\n",g.Dinic(s,t));
return ;
}
BZOJ1693: [Usaco2007 Demo]Asteroids的更多相关文章
- 【BZOJ】1693: [Usaco2007 Demo]Asteroids(匈牙利)
http://www.lydsy.com/JudgeOnline/problem.php?id=1693 裸匈牙利.. #include <cstdio> #include <cst ...
- BZOJ1629: [Usaco2007 Demo]Cow Acrobats
1629: [Usaco2007 Demo]Cow Acrobats Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 601 Solved: 305[Su ...
- BZOJ1628: [Usaco2007 Demo]City skyline
1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 256 Solved: 210[Su ...
- 【BZOJ1630/2023】[Usaco2007 Demo]Ant Counting DP
[BZOJ1630/2023][Usaco2007 Demo]Ant Counting 题意:T中蚂蚁,一共A只,同种蚂蚁认为是相同的,有一群蚂蚁要出行,个数不少于S,不大于B,求总方案数 题解:DP ...
- bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁*&&bzoj1630[Usaco2007 Demo]Ant Counting*
bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁&&bzoj1630[Usaco2007 Demo]Ant Counting 题意: t个族群,每个族群有 ...
- BZOJ1695 : [Usaco2007 Demo]Walk the Talk
观察单词表可以发现: 对于长度为3的单词,前两个字母相同的单词不超过7个 对于长度为4的单词,前两个字母相同的单词不超过35个 于是首先$O(26*26*nm)$预处理出 s1[x][i][j]表示( ...
- BZOJ 1695 [Usaco2007 Demo]Walk the Talk 链表+数学
题意:链接 方法:乱搞 解析: 出这道题的人存心报复社会. 首先这个单词表-先上网上找这个单词表- 反正总共2265个单词.然后就考虑怎么做即可了. 刚開始我没看表,找不到怎么做,最快的方法我也仅仅是 ...
- 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 ...
- bzoj1630 [Usaco2007 Demo]Ant Counting
Description Bessie was poking around the ant hill one day watching the ants march to and fro while g ...
随机推荐
- CF778A(round 402 div.2 D) String Game
题意: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. B ...
- 后TOS时代的码头数字化生产力
之前看过一篇文章是,是INFORM的副总裁写的关于以TOS外挂模式提升码头生产效能的文章.文章对外挂模式的总结挺好的,我最近也一直从事这块的工作,以此文梳理一下前面的经验,记录一下自己的感想. TOS ...
- Codeforces GYM 100741A . Queries
time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input output stan ...
- k8s集群部署之环境介绍与etcd数据库集群部署
角色 IP 组件 配置 master-1 192.168.10.11 kube-apiserver kube-controller-manager kube-scheduler etcd 2c 2g ...
- vux安装
1. 在项目里安装vux cnpm install vux --save 2. 安装vux-loader cnpm install vux-loader --save-dev 3. 安装less-lo ...
- MFC中EDIT控件实现换行
\n是C下的回撤换行.在MFC下得用\r\n.
- Caused by: java.lang.ClassNotFoundException: Cannot find class: User
源代码: <select id="selectAll" resultType="User"> select user_id uid,user_nam ...
- 清除SQL Server 2008记住的数据库地址、登录名和密码
在服务器上登录过数据库信息,并且选择了记住了密码,由于服务器数据库很多人在使用,有必要删除信息 定位到fileC:\Users\%username%\AppData\Roaming\Microsoft ...
- (14) openssl x509(签署和自签署)
主要用于输出证书信息,也能够签署证书请求文件.自签署.转换证书格式等. openssl x509工具不会使用openssl配置文件中的设定,而是完全需要自行设定或者使用该伪命令的默认值,它就像是一个完 ...
- spring-mvc jackson配置json为空不输出
使用的spring-mvc版本是4.1.6,jackson版本是2.1.4 在spring-mvc配置文件中添加以下代码就行 <mvc:annotation-driven> <mvc ...