POJ - 2391 Ombrophobic Bovines (Floyd + 二分 +ISAP)

Ombrophobic Bovines

FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain makes them shake in their hooves. They have decided to put a rain siren on the farm to let them know when rain is approaching. They intend to create a rain evacuation plan so that all the cows can get to shelter before the rain begins. Weather forecasting is not always correct, though. In order to minimize false alarms, they want to sound the siren as late as possible while still giving enough time for all the cows to get to some shelter.

The farm has F (1 <= F <= 200) fields on which the cows graze. A set of P (1 <= P <= 1500) paths connects them. The paths are wide, so that any number of cows can traverse a path in either direction.

Some of the farm's fields have rain shelters under which the cows can shield themselves. These shelters are of limited size, so a single shelter might not be able to hold all the cows. Fields are small compared to the paths and require no time for cows to traverse.

Compute the minimum amount of time before rain starts that the siren must be sounded so that every cow can get to some shelter.

Input

* Line 1: Two space-separated integers: F and P

* Lines 2..F+1: Two space-separated integers that describe a field. The first integer (range: 0..1000) is the number of cows in that field. The second integer (range: 0..1000) is the number of cows the shelter in that field can hold. Line i+1 describes field i.

* Lines F+2..F+P+1: Three space-separated integers that describe a path. The first and second integers (both range 1..F) tell the fields connected by the path. The third integer (range: 1..1,000,000,000) is how long any cow takes to traverse it.

Output

* Line 1: The minimum amount of time required for all cows to get under a shelter, presuming they plan their routes optimally. If it not possible for the all the cows to get under a shelter, output "-1".

Sample Input

3 4
7 2
0 4
2 6
1 2 40
3 2 70
2 3 90
1 3 120

Sample Output

110

Hint

OUTPUT DETAILS:

In 110 time units, two cows from field 1 can get under the shelter in that field, four cows from field 1 can get under the shelter in field 2, and one cow can get to field 3 and join the cows from that field under the shelter in field 3. Although there are other plans that will get all the cows under a shelter, none will do it in fewer than 110 time units.

题目链接:http://poj.org/problem?id=2391

题目大意:有F个田地P条路,接下来F行ai,bi表示第i个田地现在有ai头牛,有bi头牛能在这里避雨,接下来是P行ui,vi,wi,表示第i条路在ui和vi之间,牛走过这条路需要花费wi的时间。问所有牛都能避雨要花费的最短时间,如果有牛不能避雨就输出-1

思路:先用Floyd求出每两点间的最小花费时间d[ i ][ j ],二分花费时间,再建图,拆点,超级源点到点 i 之间建边 流量为ai,超级汇点到点 i+F 之间建边 流量为bi, 如果d[i][j] <= mid, i 到 j+F 建边,流量为inf,然后就是ISAP模板求最大流

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
const int N=505;
const int M=100005;
const int inf=0x3f3f3f;
const ll INF=0x3f3f3f3f3f3f;
ll mp[N][N];
int g[N],h[N],pre[N];
int first[N],tot,sum,st,ed;
int dis[N],vis[N],a[N],b[N],n,m;
struct node
{
    int v,next;
    int cap,flow;
    node(){};
    node(int tv,int tc,int tnext)
    {
        v=tv,cap=tc,next=tnext,flow=0;
    }
}e[M*2];
void adde(int u,int v,int c)
{
    e[tot]=node(v,c,first[u]);
    first[u]=tot++;
    e[tot]=node(u,0,first[v]);
    first[v]=tot++;
}
void set_h(int t)
{
    memset(h,-1,sizeof(h));
    memset(g,0,sizeof(g));
    queue<int>q;
    h[t]=0;
    q.push(t);
    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        g[h[v]]++;
        for(int i=first[v];~i;i=e[i].next)
        {
            int u=e[i].v;
            if(h[u]==-1)
            {
                h[u]=h[v]+1;
                q.push(u);
            }
        }
    }
}
int ISAP(int s,int t,int n) //ISAP模板
{
    set_h(t);
    int ans=0,u=s,d;
    while(h[s]<n)
    {
        int i=first[u];
        if(u==t) d=inf;
        for(;~i;i=e[i].next)
        {
            int v=e[i].v;
            if(e[i].cap>e[i].flow&&h[u]==h[v]+1)
            {
                u=v;
                pre[v]=i;
                d=min(d,e[i].cap-e[i].flow);
                if(u==t)
                {
                    while(u!=s)
                    {
                        int j=pre[u];
                        e[j].flow+=d;
                        e[j^1].flow-=d;
                        u=e[j^1].v;
                    }
                    ans+=d;
                    d=inf;
                }
                break;
            }
        }
        if(i==-1)
        {
            if(--g[h[u]]==0) break;
            int hmin=n-1;
            for(int j=first[u];~j;j=e[j].next)
                if(e[j].cap>e[j].flow)
                hmin=min(hmin,h[e[j].v]);
            h[u]=hmin+1;
            g[h[u]]++;
            if(u!=s) u=e[pre[u]^1].v;
        }
    }
    return ans;
}
int build(ll w) //建图
{
    tot=0;
    memset(first,-1,sizeof(first));
    st=0,ed=2*n+1; //超级源点汇点
    for(int i=1; i<=n; i++)
    {
        adde(st,i,a[i]);
        adde(i+n,ed,b[i]);
        for(int j=1; j<=n; j++)
            if(mp[i][j]<=w)
                adde(i,j+n,inf);
    }
    return ISAP(st,ed,2*n+2);
}
void solve()
{
    ll maxx=0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            if(mp[i][j]<INF&&mp[i][j]>maxx)
                maxx=mp[i][j];
    if(build(maxx)<sum) printf("-1\n");
    else
    {
        ll l=0,r=maxx,ans;
        while(l<=r)
        {
            ll mid=(l+r)>>1;
            if(build(mid)>=sum)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        printf("%lld\n",ans);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    sum=0;
    int u,v;
    ll w;
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        sum+=a[i];
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
            if(i==j) mp[i][j]=0;
            else mp[i][j]=INF;
    }
    for(int i=0; i<m; i++)
    {
        scanf("%d%d%lld",&u,&v,&w);
        if(w<mp[u][v]) mp[u][v]=mp[v][u]=w;
    }
    for(int k=1; k<=n; k++) //Floyd
        for(int i=1; i<=n; i++)
            if(mp[i][k]<INF)
                for(int j=1; j<=n; j++)
                    mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
    solve();
    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、付费专栏及课程。

余额充值