E - Island Transport

本文介绍了一种算法,用于计算在一系列遵循特定规则的岛屿间航线中,从最西边到最东边岛屿的最大运输能力。该算法通过构建图模型并使用最大流算法求解。

https://vjudge.net/contest/402729#problem/E

In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies on the ships.
  You have a transportation company there. Some routes are opened for passengers. Each route is a straight line connecting two different islands, and it is bidirectional. Within an hour, a route can transport a certain number of passengers in one direction. For safety, no two routes are cross or overlap and no routes will pass an island except the departing island and the arriving island. Each island can be treated as a point on the XY plane coordinate system. X coordinate increase from west to east, and Y coordinate increase from south to north.
  The transport capacity is important to you. Suppose many passengers depart from the westernmost island and would like to arrive at the easternmost island, the maximum number of passengers arrive at the latter within every hour is the transport capacity. Please calculate it.

Input

  The first line contains one integer T (1<=T<=20), the number of test cases.
  Then T test cases follow. The first line of each test case contains two integers N and M (2<=N,M<=100000), the number of islands and the number of routes. Islands are number from 1 to N.
  Then N lines follow. Each line contain two integers, the X and Y coordinate of an island. The K-th line in the N lines describes the island K. The absolute values of all the coordinates are no more than 100000.
  Then M lines follow. Each line contains three integers I1, I2 (1<=I1,I2<=N) and C (1<=C<=10000) . It means there is a route connecting island I1 and island I2, and it can transport C passengers in one direction within an hour.
  It is guaranteed that the routes obey the rules described above. There is only one island is westernmost and only one island is easternmost. No two islands would have the same coordinates. Each island can go to any other island by the routes.

Output

  For each test case, output an integer in one line, the transport capacity.

Sample Input

2
5 7
3 3
3 0
3 1
0 0
4 5
1 3 3
2 3 4
2 4 3
1 5 6
4 5 3
1 4 4
3 4 2
6 7
-1 -1
0 1
0 2
1 0
1 1
2 3
1 2 1
2 3 6
4 5 5
5 6 3
1 4 6
2 5 5
3 6 4

Sample Output

9
6

代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
const ll maxn=2e5+10,inf=1<<29;
ll n,m,k,s,t,h[maxn],cur[maxn],cnt=1,vis[maxn];
struct node{
    ll to,nt,w;
}e[maxn];
void add(ll u,ll v,ll w)
{
    e[++cnt]={v,h[u],w};
    h[u]=cnt;
}
queue<ll>q;
bool bfs()
{
    for(int i=1;i<=n;i++)
        vis[i]=0;
    vis[s]=1;
    q.push(s);
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        cur[u]=h[u];
        for(ll i=h[u];i;i=e[i].nt)
        {
            ll v=e[i].to,w=e[i].w;
            if(w&&!vis[v])
            {
                vis[v]=vis[u]+1;
                q.push(v);
            }
        }
    }
    return vis[t];

}
ll dfs(ll u,ll flow)
{
    if(u==t)
        return flow;
    ll res=flow;
    for(ll i=cur[u];i;i=e[i].nt)
    {
        ll v=e[i].to,w=e[i].w;
        if(w&&vis[u]+1==vis[v])
        {
            ll now=dfs(v,min(res,w));
            if(!now)
                vis[v]=1;
            else
            {
                e[i].w-=now;
                e[i^1].w+=now;
                res-=now;
            }
        }
        if(!res)
        return flow;
    }
    return flow-res;
}
struct nnode{
    int x,y;
    int id;
}a[maxn];
bool cmp(nnode p,nnode q)
{
    if(p.x!=q.x)
    return p.x<q.x;
    else
        return p.y<q.y;
}
bool bmp(nnode p,nnode q)
{
    return p.id<q.id;
}
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        memset(cur,0,sizeof(cur));
        memset(h,0,sizeof(h));
        scanf("%lld %lld",&n,&m);
        int max1=0,min1=inf,k1,k2;
        for(int i=1;i<=n;i++)
        {
            a[i].id=i;
            scanf("%d %d",&a[i].x,&a[i].y);
            if(a[i].x>max1)
            {
                max1=a[i].x;
                k1=i;
            }
            if(a[i].x<min1)
            {
                min1=a[i].x;
                k2=i;
            }
        }
        s=k2;
        t=k1;
        cnt=1;
        for(int i=1;i<=m;i++)
        {
            ll u,v,w;
            scanf("%lld %lld %lld",&u,&v,&w);
            add(u,v,w);
            add(v,u,w);
        }
        ll ans=0;
        while(!q.empty())
            q.pop();
        while(bfs())
        {
            ans+=dfs(s,inf);
            //cout<<ans<<endl;
        }
        printf("%lld\n",ans);
    }

    return 0;
}

 

代码下载地址: https://pan.quark.cn/s/bc087ffa872a "测控电路课后习题详解"文件.pdf是一份极具价值的学术资料,其中系统地阐述了测控电路的基础理论、系统构造、核心特性及其实际应用领域。 以下是对该文献的深入解读和系统梳理:1.1测控电路在测控系统中的核心功能测控电路在测控系统的整体架构中扮演着不可或缺的角色。 它承担着对传感器输出信号进行放大、滤除杂音、提取有效信息等关键任务,并且依据测量与控制的需求,执行必要的计算、处理与变换操作,最终输出能够驱动执行机构运作的指令信号。 测控电路作为测控系统中最具可塑性的部分,具备易于放大信号、转换模式、传输数据以及适应多样化应用场景的优势。 1.2决定测控电路精确度的关键要素影响测控电路精确度的核心要素包括:(1)噪声与干扰的存在;(2)失调现象与漂移效应,尤其是温度引起的漂移;(3)线性表现与保真度水平;(4)输入输出阻抗的特性影响。 在这些要素中,噪声干扰与失调漂移(含温度效应)是最为关键的因素,需要给予高度关注。 1.3测控电路的适应性表现测控电路在测控系统中展现出高度的适应性,具体表现在:* 具备选择特定信号、灵活实施各类转换以及进行信号处理与运算的能力* 实现模数转换与数模转换功能* 在直流与交流、电压与电流信号之间进行灵活转换* 在幅值、相位、频率与脉宽信号等不同参数间进行转换* 实现量程调整功能* 对信号实施多样化的处理与运算,如计算平均值、差值、峰值、绝对值,进行求导数、积分运算等,以及实现非线性环节的线性化处理、逻辑判断等操作1.4测量电路输入信号类型对电路结构设计的影响测量电路的输入信号类型对其电路结构设计产生显著影响。 依据传感器的类型差异,输入信号的形态也呈现多样性。 主要可分为...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值