poj 3308(最小点权覆盖、最小割)
题目链接:http://poj.org/problem?id=3308
思路:裸的最小点权覆盖,建立超级源点和超级汇点,将源点与行相连,容量为这行消灭敌人的代价,将列与汇点相连,容量为这列消灭敌人的代价,对于每一个敌人(x,y),连边x->y,容量为inf,这样就说明选取的点覆盖了那些边(敌人),然后跑最大流求最小割即可。
PS:这里是乘积最小,要取对数转化为和最小。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define MAXN 222
#define MAXM 444444
#define inf 1<<30 struct Edge{
int v,next;
double cap;
}edge[MAXM]; int n,m,T,NE,NV,vs,vt;
int head[MAXN]; void Insert(int u,int v,double cap)
{
edge[NE].v=v;
edge[NE].cap=cap;
edge[NE].next=head[u];
head[u]=NE++; edge[NE].v=u;
edge[NE].cap=;
edge[NE].next=head[v];
head[v]=NE++;
} int level[MAXN],gap[MAXN];
void bfs(int vt)
{
memset(level,-,sizeof(level));
memset(gap,,sizeof(gap));
level[vt]=;
gap[level[vt]]++;
queue<int>que;
que.push(vt);
while(!que.empty()){
int u=que.front();
que.pop();
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].v;
if(level[v]<){
level[v]=level[u]+;
gap[level[v]]++;
que.push(v);
}
}
}
} int pre[MAXN],cur[MAXN];
double SAP(int vs,int vt)
{
bfs(vt);
memset(pre,-,sizeof(pre));
memcpy(cur,head,sizeof(head));
double maxflow=,aug=inf;
int u=pre[vs]=vs;
gap[]=NV;
while(level[vs]<NV){
bool flag=false;
for(int &i=cur[u];i!=-;i=edge[i].next){
int v=edge[i].v;
if(edge[i].cap>&&level[u]==level[v]+){
flag=true;
pre[v]=u;
u=v;
aug=min(aug,edge[i].cap);
if(v==vt){
maxflow+=aug;
for(u=pre[v];v!=vs;v=u,u=pre[u]){
edge[cur[u]].cap-=aug;
edge[cur[u]^].cap+=aug;
}
aug=inf;
}
break;
}
}
if(flag)continue;
int minlevel=NV;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].v;
if(edge[i].cap>&&level[v]<minlevel){
minlevel=level[v];
cur[u]=i;
}
}
if(--gap[level[u]]==)break;
level[u]=minlevel+;
gap[level[u]]++;
u=pre[u];
}
return maxflow;
} int main()
{
double x,y;
int _case,u,v;
scanf("%d",&_case);
while(_case--){
scanf("%d%d%d",&n,&m,&T);
NE=;
memset(head,-,sizeof(head));
vs=,vt=n+m+,NV=vt+;
for(int i=;i<=n;i++){
scanf("%lf",&x);
Insert(vs,i,log(x));
}
for(int i=;i<=m;i++){
scanf("%lf",&y);
Insert(i+n,vt,log(y));
}
while(T--){
scanf("%d%d",&u,&v);
Insert(u,v+n,inf);
}
double ans=SAP(vs,vt);
printf("%.4f\n",exp(ans));
}
return ;
}
poj 3308(最小点权覆盖、最小割)的更多相关文章
- POJ2125 Destroying The Graph 二分图 + 最小点权覆盖 + 最小割
思路来源:http://blog.csdn.net/lenleaves/article/details/7873441 求最小点权覆盖,同样求一个最小割,但是要求出割去了那些边, 只要用最终的剩余网络 ...
- POJ 3308 Paratroopers(最小点权覆盖)(对数乘转加)
http://poj.org/problem?id=3308 r*c的地图 每一个大炮可以消灭一行一列的敌人 安装消灭第i行的大炮花费是ri 安装消灭第j行的大炮花费是ci 已知敌人坐标,同时消灭所有 ...
- POJ 3308 Paratroopers(最大流最小割の最小点权覆盖)
Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...
- POJ - 3308 Paratroopers (最小点权覆盖)
题意:N*M个格点,K个位置会有敌人.每行每列都有一门炮,能打掉这一行(列)上所有的敌人.每门炮都有其使用价值.总花费是所有使用炮的权值的乘积.求最小的总花费. 若每门炮的权值都是1,就是求最小点覆盖 ...
- POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)
题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...
- POJ 3308 Paratroopers (对数转换+最小点权覆盖)
题意 敌人侵略r*c的地图.为了消灭敌人,可以在某一行或者某一列安置超级大炮.每一个大炮可以瞬间消灭这一行(或者列)的敌人.安装消灭第i行的大炮消费是ri.安装消灭第j行的大炮消费是ci现在有n个敌人 ...
- poj 3308 Paratroopers(二分图最小点权覆盖)
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8954 Accepted: 2702 Desc ...
- poj 2125 Destroying The Graph (最小点权覆盖)
Destroying The Graph http://poj.org/problem?id=2125 Time Limit: 2000MS Memory Limit: 65536K ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
随机推荐
- Android Exception 11(baidumapsdk(15405): Authentication Error errorcode: 102 uid)
08-12 16:06:12.622: E/baidumapsdk(15405): Authentication Error errorcode: 102 uid: null appid -1 msg ...
- c++11 Using Callable Objects, std::thread, std::bind, std::async, std::call_once
- Com与.Net互操作
Com与.Net互操作 .Net调用Com组件主要分为两类:静态调用及动态调用.所谓静态调用:指通过tlbimp.exe命名产生Com组件在.Net环境下的包装类,然后通过这个包装类来访问Com组件. ...
- Wireshark-配合tcpdump对Android(安卓)手机抓包
环境:Windows, 安装真机(可以获取Root权限), adb, Wireshark, tcpdump 原理: 使用 tcpdump 进行抓包, 然后用 Wireshark 进行分析 1.获取手机 ...
- 重写kinect2_viewer,编译高博kinect2在orbslam2上跑的程序(解决cmakefile中库依赖和头文件的问题)
该方法详述了高博kinect2_viewer的编译过程 //...................................................................... ...
- 零样本学习 - (Zero shot learning,ZSL)
https://zhuanlan.zhihu.com/p/41846072 https://zhuanlan.zhihu.com/p/38418698 https://zhuanlan.zhihu.c ...
- intellij idea中修改代码生成的模板
File -- Settings -- Editor -- Code Style -- File and Code Templates 主要是修改了注释 /** * ${DESCRIPTION} * ...
- unity, List namespace
如果要使用List,需要using System.Collections.Generic;
- Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)
D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- 微信小程度腾讯地图SDK使用方法
在开发过程中,不少人肯定遇到过要用到地图,那么在小程序里,腾讯也给出了相应的SDK供我们来使用.那么接下来,就介绍下如何使用该SDK实现获取经纬度然后显示当前用户所在地址 首先第一步:下载腾讯地图SD ...