Description
It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the Mars. Recently, the commanders of the Earth are informed by their spies that the invaders of Mars want to land some paratroopers in them × n grid yard of one their main weapon factories in order to destroy it. In addition, the spies informed them the row and column of the places in the yard in which each paratrooper will land. Since the paratroopers are very strong and well-organized, even one of them, if survived, can complete the mission and destroy the whole factory. As a result, the defense force of the Earth must kill all of them simultaneously after their landing.
In order to accomplish this task, the defense force wants to utilize some of their most hi-tech laser guns. They can install a gun on a row (resp. column) and by firing this gun all paratroopers landed in this row (resp. column) will die. The cost of installing a gun in the ith row (resp. column) of the grid yard is ri (resp.ci ) and the total cost of constructing a system firing all guns simultaneously is equal to the product of their costs. Now, your team as a high rank defense group must select the guns that can kill all paratroopers and yield minimum total cost of constructing the firing system.
Input
Input begins with a number T showing the number of test cases and then,T test cases follow. Each test case begins with a line containing three integers 1 ≤m ≤ 50 , 1 ≤ n ≤ 50 and 1 ≤ l ≤ 500 showing the number of rows and columns of the yard and the number of paratroopers respectively. After that, a line withm positive real numbers greater or equal to 1.0 comes where the ith number isri and then, a line with n positive real numbers greater or equal to 1.0 comes where theith number is ci. Finally, l lines come each containing the row and column of a paratrooper.
Output
For each test case, your program must output the minimum total cost of constructing the firing system rounded to four digits after the fraction point.
Sample Input
1 4 4 5 2.0 7.0 5.0 2.0 1.5 2.0 2.0 8.0 1 1 2 2 3 3 4 4 1 4
Sample Output
16.0000
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
const int inf=(1<<28);
using namespace std;
#define maxn 500000
struct edge
{
int u,v,next,pre;
double f;
}e[2*maxn];
int num,rnum;
int head[maxn],rhead[maxn];
int d[maxn];
int numb[maxn];
int start[maxn];
int n,m;//见图后的点数(1->n)和原图边数
int p[maxn];
int source,sink;
//要初始化source 和 sink,重定义n
void Init()
{
memset(head,-1,sizeof(head));
memset(rhead,-1,sizeof(rhead));
memset(p,-1,sizeof(p));
num=0;
return ;
}
void BFS()
{
int i,j;
for(i=1;i<=n;i++)
{
d[i]=n;
numb[i]=0;
}
int Q[maxn],head(0),tail(0);
d[sink]=0;
numb[0]=1;
Q[++tail]=sink;
while(head<tail)
{
i=Q[++head];
for(j=rhead[i];j!=-1;j=e[j].pre)
{
if(e[j].f==0||d[e[j].u]<n)
continue;
d[e[j].u]=d[i]+1;
numb[d[e[j].u]]++;
Q[++tail]=e[j].u;
}
}
return ;
}
double Augment()
{
int i;
double tmp=inf;
for(i=p[sink];i!=-1;i=p[e[i].u])
{
if(tmp>e[i].f)
tmp=e[i].f;
}
for(i=p[sink];i!=-1;i=p[e[i].u])
{
e[i].f-=tmp;
e[i^1].f+=tmp;
}
return tmp;
}
int Retreat(int &i)
{
int tmp,j,mind(n-1);
for(j=head[i];j!=-1;j=e[j].next)
{
if(e[j].f>0&&d[e[j].v]<mind)
mind=d[e[j].v];
}
tmp=d[i];
d[i]=mind+1;
numb[tmp]--;
numb[d[i]]++;
if(i!=source)
i=e[p[i]].u;
return numb[tmp];
}
double maxflow()
{
double flow(0);
int i,j;
BFS();
for(i=1;i<=n;i++)
start[i]=head[i];
i=source;
while(d[source]<n)
{
for(j=start[i];j!=-1;j=e[j].next)
if(e[j].f>0&&d[i]==d[e[j].v]+1)
break;
if(j!=-1)
{
start[i]=j;
p[e[j].v]=j;
i=e[j].v;
if(i==sink)
{
flow+=Augment();
i=source;
}
}
else
{
start[i]=head[i];
if(Retreat(i)==0)
break;
}
}
return flow;
}
//a->b=c;
void addedge(int a,int b,double c)
{
e[num].next=head[a];
head[a]=num;
e[num].pre=rhead[b];
rhead[b]=num;
e[num].f=c;
e[num].u=a;
e[num++].v=b;
e[num].next=head[b];
head[b]=num;
e[num].pre=rhead[a];
rhead[a]=num;
e[num].u=b;
e[num].v=a;
e[num++].f=0;
return ;
}
int main()
{
int ci;scanf("%d",&ci);
while(ci--)
{
Init();
int tn,tm,tp;scanf("%d%d%d",&tn,&tm,&tp);
source=1,sink=tn+tm+2;
n=tn+tm+2;
for(int i=1;i<=tn;i++)
{
double x;scanf("%lf",&x);x=log(x);
addedge(source,i+1,x);
}
for(int i=1;i<=tm;i++)
{
double x;scanf("%lf",&x);x=log(x);
addedge(i+1+tn,sink,x);
}
for(int i=0;i<tp;i++)
{
int u,v;scanf("%d%d",&u,&v);
addedge(u+1,v+tn+1,inf);
}
double cnt=maxflow();
cnt=exp(cnt);
printf("%.4lf\n",cnt);
}
return 0;
}
本文深入探讨了AI音视频处理领域中的视频分割与语义识别技术,介绍了如何通过计算机视觉算法实现对视频内容的智能解析与理解。包括视频分割的方法、语义识别的应用场景及其实现过程,旨在为开发者提供有效的解决方案,提升音视频处理的智能化水平。

被折叠的 条评论
为什么被折叠?



