LOI Online Judge 33. 【2017.4.1】面包店

题目描述
Peacefuldoge 想要开面包店,国家有 n 个城市,m 条双向道路。他需要向一些仓库进原料,而他的国家有 k 个城市有仓库。很不幸,根据这个国家的法律,他不能在这些有仓库的城市开面包店。(所以他只能开在其他地方了 QAQ)

当然,肯定有运费,对于每条路每运 1 千米就要支付 1 元。现在请问他最少要支付多少运费才能在一个城市开上面包店。当然,有可能根本就没法开面包店,那么就输出-1。

输入格式
第一行 3 个数 n,m,k
表示 n 个城市 m条道路 k 个仓库

接下来 m行

每行包括三个数 u,v,l,表示从 u 到 v 的距离为 l 的道路

接下来一行 k 个数,表示有仓库的城市编号。

输出格式
一个数,如果可以开面包店,那么输出花费最小值。

否则输出”−1”

样例一
input

5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
output

3

思路:
这里写图片描述
假设黑点是仓库,其余点为可建立面包店的城市
则我们必会在两个红点中择小者,而不会选择绿点
所以只需在 所有 与仓库直接相连的 可建立面包店的城市中 选择路程最小的一个即可。
如果没有,输出-1

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100000+50;
int s[maxn],e[maxn],v[maxn],n,m,ans=-1,k,x;
bool can[maxn];
int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&s[i],&e[i],&v[i]);
    }
    for(int i=1;i<=k;i++){
        scanf("%d",&x);
        can[x]=1;
    }
    for(int i=1;i<=m;i++){
        if((can[s[i]]+can[e[i]])==1){
            if((ans==-1)||ans>v[i]) ans=v[i];
        }
    }
     printf("%d",ans);

    return  0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我地道的翻译:The differential variational inequalities ((DVIs), for short) are useful for the study of models involving both dynamics and constraints in the form of in￾equalities. They arise in many applications: electrical circuits with ideal diodes, Coulomb friction problems for contacting bodies, economical dynamics, dynamic traffic networks. Pang and Stewart [26], [27] established the existence, unique￾ness, and Lipschitz dependence of solutions subject to boundary conditions for (DVIs) in finite dimensional spaces. Han and Pang investigated a class of dif￾ferential quasi-variational inequalities in [11], and Li, Huang and O’Regan [18] studied a class of differential mixed variational inequalities in finite dimensional Well-Posedness of Differential Mixed Quasi-Variational-Inequalities 137 spaces. Gwinner [8] obtained an equivalence result between (DVIs) and projected dynamical systems. In [9] he also proved a stability property for (DVIs) by using the monotonicity method of Browder and Minty, and Mosco set convergence. Chen and Wang [4] studied dynamic Nash equilibrium problems which have the formulation of differential mixed quasi-variational inequalities. Elastoplastic contact problems can also be incorporated into (DMQVIs) formulation because general dynamic processes in the nonsmooth unilateral contact problems are governed by quasi-variational inequalities. A numerical study for nonsmooth contact problems with Tresca friction can be found in [10], Liu, Loi and Obukhovskii [19] studied the existence and global bifurcation for periodic solutions of a class of (DVIs) by using the topological degree theory for multivalued maps and the method of guiding functions. For more details about (DVIs) we refer to [3], [30], [12], [22]–[21].
最新发布
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值