HDU - 5988 Coding Contest (最小费用最大流)

Coding Contest

 

A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the uiui-th block to the vivi-th block. Your task is to solve the lunch issue. According to the arrangement, there are sisi competitors in the i-th block. Limited to the size of table, bibi bags of lunch including breads, sausages and milk would be put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would be so many wires on the path.
For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of pipi to touch
the wires and affect the whole networks. Moreover, to protect these wires, no more than cici competitors are allowed to walk through the i-th path.
Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing.

Input

The first line of input contains an integer t which is the number of test cases. Then t test cases follow.
For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and bibi (sisi , bibi ≤ 200).
Each of the next M lines contains three integers uiui , vivi and ci(cici(ci ≤ 100) and a float-point number pipi(0 < pipi < 1).
It is guaranteed that there is at least one way to let every competitor has lunch.

Output

For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.

Sample Input

1
4 4
2 0
0 3
3 0
0 3
1 2 5 0.5
3 2 5 0.5
1 4 5 0.5
3 4 5 0.5

Sample Output

0.50

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988

题目大意:t组输入,操场被分成n块,有m条路,每一块开始有ai个参赛人员,有bi份午饭, 每条路从ui到vi 最多能通过ci个人,每个人通过导致道路网络瘫痪的概率是pi,其中第一个通过这条路的人不会导致道路瘫痪。问每个人都吃到午饭道路瘫痪的最小概率。

把概率取log,把乘法变成加法,然后就是最小费用最大流模板

代码:

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int N=105;
const int M=50005;
const double eps=1e-7;
const int inf=0x3f3f3f3f;
double dis[N];
int pre[N],vis[N];
int maxflow,first[N],tot;
struct node
{
    int v,nex,cap,flow;
    double cost;
    node(){};
    node(int _v,int _c,int _nex,double _cost)
    {
        v=_v,cap=_c,nex=_nex,cost=_cost,flow=0;
    }
}e[M];
void init()
{
    mem(first,-1);
    tot=maxflow=0;
}
void add(int u,int v,int c,double cost)
{
    e[tot]=node(v,c,first[u],cost);
    first[u]=tot++;
    e[tot]=node(u,0,first[v],-cost);
    first[v]=tot++;
}
double spfa(int s,int t,int n)
{
    int i,u,v;
    queue<int>q;
    for(int i=1; i<=n; i++) vis[i]=0,dis[i]=inf,pre[i]=-1;
    vis[s]=1;
    dis[s]=0;
    q.push(s);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        vis[u]=0;
        for(int i=first[u]; i!=-1; i=e[i].nex)
        {
            v=e[i].v;
            if(e[i].cap>e[i].flow&&dis[v]>dis[u]+e[i].cost+eps)
            {
                dis[v]=dis[u]+e[i].cost;
                pre[v]=i;
                if(!vis[v])
                {
                    q.push(v);
                    vis[v]=1;
                }
            }
        }
    }
    if(dis[t]==inf)
        return 0;
    return 1;
}
double MCMF(int s,int t,int n)
{
    int d;
    double mincost=0;
    while(spfa(s,t,n))
    {
        d=inf;
        for(int i=pre[t]; i!=-1; i=pre[e[i^1].v])
            d=min(d,e[i].cap-e[i].flow);
        maxflow+=d;
        for(int i=pre[t]; i!=-1; i=pre[e[i^1].v])
        {
            e[i].flow+=d;
            e[i^1].flow-=d;
        }
        mincost+=dis[t]*d;
    }
    return mincost;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        init();
        int n,m,x,y,w;
        double z;
        scanf("%d%d",&n,&m);
        int st=n+1,ed=n+2;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&x,&y);
            add(st,i,x,0);
            add(i,ed,y,0);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d%lf",&x,&y,&w,&z);
            z=-log2(1-z); 
            if(w) add(x,y,1,0);
            if(w>1) add(x,y,w-1,z);
        }
        double mincost=MCMF(st,ed,n+2);
        mincost=pow(2,-mincost);
        printf("%.2f\n",1-mincost);
    }
    return 0;
}

 

分数阶傅里叶变换(Fractional Fourier Transform, FRFT)是对传统傅里叶变换的拓展,它通过非整数阶的变换方式,能够更有效地处理非线性信号以及涉及时频局部化的问题。在信号处理领域,FRFT尤其适用于分析非平稳信号,例如在雷达、声纳和通信系统中,对线性调频(Linear Frequency Modulation, LFM)信号的分析具有显著优势。LFM信号是一种频率随时间线性变化的信号,因其具有宽频带和良好的时频分辨率,被广泛应用于雷达和通信系统。FRFT能够更精准地捕捉LFM信号的时间和频率信息,相比普通傅里叶变换,其性能更为出色。 MATLAB是一种强大的数值计算和科学计算工具,拥有丰富的函数库和用户友好的界面。在MATLAB中实现FRFT,通常需要编写自定义函数或利用信号处理工具箱中的相关函数。例如,一个名为“frft”的文件可能是用于执行分数阶傅里叶变换的MATLAB脚本或函数,并展示其在信号处理中的应用。FRFT的正确性验证通常通过对比变换前后信号的特性来完成,比如评估信号的重构质量、信噪比等。具体而言,可以通过计算原始信号与经过FRFT处理后的信号之间的相似度,或者对比LFM信号的关键参数(如初始频率、扫频率和持续时间)是否在变换后得到准确恢复。 在MATLAB代码实现中,通常包含以下步骤:首先,生成LFM信号模型,设定其初始频率、扫频率、持续时间和采样率等参数;其次,利用自定义的frft函数对LFM信号进行分数阶傅里叶变换;接着,使用MATLAB的可视化工具(如plot或imagesc)展示原始信号的时域和频域表示,以及FRFT后的结果,以便直观对比;最后,通过计算均方误差、峰值信噪比等指标来评估FRFT的性能。深入理解FRFT的数学原理并结合MATLAB编程技巧,可以实现对LFM信号的有效分析和处理。这个代码示例不仅展示了理论知识在
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值