POJ 3228 Gold Transportation (二分+最大流) (Dinic + 二分 或 EK)

Gold Transportation
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2407 Accepted: 858

Description

Recently, a number of gold mines have been discovered in Zorroming State. To protect this treasure, we must transport this gold to the storehouses as quickly as possible. Suppose that the Zorroming State consists of N towns and there are M bidirectional roads among these towns. The gold mines are only discovered in parts of the towns, while the storehouses are also owned by parts of the towns. The storage of the gold mine and storehouse for each town is finite. The truck drivers in the Zorroming State are famous for their bad temper that they would not like to drive all the time and they need a bar and an inn available in the trip for a good rest. Therefore, your task is to minimize the maximum adjacent distance among all the possible transport routes on the condition that all the gold is safely transported to the storehouses.

Input

The input contains several test cases. For each case, the first line is integer N(1<=N<=200). The second line is N integers associated with the storage of the gold mine in every towns .The third line is also N integers associated with the storage of the storehouses in every towns .Next is integer M(0<=M<=(n-1)*n/2).Then M lines follow. Each line is three integers x y and d(1<=x,y<=N,0<d<=10000), means that there is a road between x and y for distance of d. N=0 means end of the input.

Output

For each case, output the minimum of the maximum adjacent distance on the condition that all the gold has been transported to the storehouses or "No Solution".

Sample Input

4
3 2 0 0
0 0 3 3
6
1 2 4
1 3 10
1 4 12
2 3 6
2 4 8
3 4 5
0

Sample Output

6

Source

 
 
题意:有N座town 每座town都有一定数量gold和仓库 仓库的容量是有限的 有M条双向路径 求把所有的gold 运到仓库最小的最大距离是多少。

思路:跟前几天做的那道 poj 2112 Optimal Milking    的思想是一样的,建图时,超级源点与gold相连 容量为gold的数量,超级汇点与仓库相连,容量为仓库的容量,其余边为无穷。用二分枚举求出最小的最距离
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>

using namespace std;

const int VM=220;
const int EM=50010;
const int INF=0x3f3f3f3f;

int n,m,src,des,map[VM][VM],dis[VM][VM];
int total,gold[VM],store[VM],dep[VM];

void buildgraph(int x){
    memset(map,0,sizeof(map));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(dis[i][j]<=x)
                map[i][j]=INF;
    for(int i=1;i<=n;i++){
        map[src][i]=gold[i];
        map[i][des]=store[i];
    }
}

int BFS(){
    queue<int> q;
    while(!q.empty())
        q.pop();
    memset(dep,-1,sizeof(dep));
    dep[src]=0;
    q.push(src);
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int v=src;v<=des;v++)
            if(map[u][v]>0 && dep[v]==-1){
                dep[v]=dep[u]+1;
                q.push(v);
            }
    }
    return dep[des]!=-1;
}

int DFS(int u,int minx){
    if(u==des)
        return minx;
    int tmp;
    for(int v=src;v<=des;v++)
        if(map[u][v]>0 && dep[v]==dep[u]+1 && (tmp=DFS(v,min(minx,map[u][v])))){
            map[u][v]-=tmp;
            map[v][u]+=tmp;
            return tmp;
        }
    dep[u]=-1;
    return 0;
}

int Dinic(){
    int ans=0,tmp;
    while(BFS()){
        while(1){
            tmp=DFS(src,INF);
            if(tmp==0)
                break;
            ans+=tmp;
        }
    }
    return ans;
}

int main(){

    //freopen("input.txt","r",stdin);

    while(~scanf("%d",&n) && n){
        memset(dis,0x3f,sizeof(dis));
        total=0;
        src=0,  des=n+1;
        for(int i=1;i<=n;i++){
            scanf("%d",&gold[i]);
            total+=gold[i];     //宝藏的总数
        }
        for(int i=1;i<=n;i++)
            scanf("%d",&store[i]);
        scanf("%d",&m);
        int u,v,w;
        while(m--){
            scanf("%d%d%d",&u,&v,&w);
            dis[u][v]=dis[v][u]=w;
        }
        int l=0,r=100010;
        int ans=-1,tmp;
        while(l<=r){
            int mid=(l+r)>>1;
            buildgraph(mid);
            tmp=Dinic();
            if(tmp==total){
                ans=mid;
                r=mid-1;
            }else
                l=mid+1;
        }
        if(ans==-1)
            printf("No Solution\n");
        else
            printf("%d\n",ans);
    }
    return 0;
}

 

 
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

const int INF=0x3f3f3f3f;
const int VM=250;
const int EM=20010;

int pre[VM],mat[VM][VM],dis[VM][VM];
int gold[VM],stor[VM];
int n,m,total,src,des;

void build(int num){    //在当前距离下 给通过的路径
    memset(mat,0,sizeof(mat));
    int i,j;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(dis[i][j]<=num)
                mat[i][j]=INF;
    for(i=1;i<=n;i++){
        mat[src][i]=gold[i];
        mat[i][des]=stor[i];
    }
}

bool BFS(){
    int q[VM+5];
    memset(pre,0xff,sizeof(pre)); //-1
    int front=0,rear=0;
    pre[src]=0;
    q[rear++]=src;
    while(front!=rear){
        int u=q[front++];
        front=front%VM;
        for(int v=1;v<=des;v++){
            if(pre[v]!=-1 || mat[u][v]==0)
                continue;
            pre[v]=u;
            if(v==des)
                return 1;
            q[rear++]=v;
            rear=rear%VM;
        }
    }
    return 0;
}

int EK(){
    int res=0;
    while(BFS()){
        int tmp=INF;
        for(int i=des;i!=src;i=pre[i])
            tmp=min(tmp,mat[pre[i]][i]);
        res+=tmp;
        for(int i=des;i!=src;i=pre[i]){
            mat[pre[i]][i]-=tmp;
            mat[i][pre[i]]+=tmp;
        }
    }
    return res;
}

int main(){

    //freopen("input.txt","r",stdin);

    int u,v,w;
    while(~scanf("%d",&n) && n){
        memset(dis,0x3f,sizeof(dis));
        total=0;    //total是总的gold数
        src=0,des=n+1;
        for(int i=1;i<=n;i++){
            scanf("%d",&gold[i]);
            total+=gold[i];
        }
        for(int i=1;i<=n;i++)
            scanf("%d",&stor[i]);
        scanf("%d",&m);
        while(m--){
            scanf("%d%d%d",&u,&v,&w);
            dis[u][v]=w;
            dis[v][u]=w;
        }
        int l=0,r=10001;
        int ans=-1;
        while(l<=r){
            int mid=(l+r)>>1;
            build(mid);
            int sum=EK();
            if(sum>=total){
                ans=mid;
                r=mid-1;
            }else
                l=mid+1;
        }
        if(ans==-1)
            printf("No Solution\n");
        else
            printf("%d\n",ans);
    }
    return 0;
}

 

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值