Problem Description
There are n planets in the MOT galaxy, and each planet has a unique number from ∼n. Each planet is connected to other planets through some transmission channels. There are m transmission channels in the galaxy. Each transmission channel connects two different planets, and each transmission channel has a length.
The residents of the galaxy complete the interplanetary voyage by spaceship. Each spaceship has a level. The spacecraft can be upgraded several times. It can only be upgraded level each time, and the cost is c. Each upgrade will increase the transmission distance by d and the number of transmissions channels by e to the spacecraft. The spacecraft can only pass through channels that are shorter than or equal to its transmission distance. If the number of transmissions is exhausted, the spacecraft can no longer be used.
Alice initially has a -level spacecraft with transmission distance of and transmission number of . Alice wants to know how much it costs at least, in order to transfer from planet to planet n. Input
Each test file contains a single test case. In each test file:
The first line contains n, m, indicating the number of plants and the number of transmission channels.
The second line contains c, d, e, representing the cost, the increased transmission distance, and the increased number of transmissions channels of each upgrade, respectively.
Next m lines, each line contains u,v,w, meaning that there is a transmission channel between u and v with a length of w.(≤n≤, n-≤m≤,≤u,v≤n ,≤c,d,e,w≤)
(The graph has no self-loop , no repeated edges , and is connected) Output
Output a line for the minimum cost. Output - if she can’t reach. Sample Input Sample Output 题意
有n个点,编号从1到n,有m条边,每条边有一个长度w。
Alice有一艘飞船,Alice可以给它升级很多次(无限),每升级一次需要花费c,升级一次之后飞船单次可飞行距离增加d,可飞行次数增加e。如果飞船需要飞过一条边,就需要满足单次可飞行距离≥这条路的长度同时可飞行次数不为0。
现在Alice在编号为1的点,她的飞船为0级,单次可飞行距离和可飞行次数都为0,请你求出最小的花费使得Alice可以到达n点,如果不能到达n则输出-。
   // 二分更新次数
//无环无向图且联通 ,就是树
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define N 100100
#define inf 1e12
int n,m,cnt;
ll c,d,E;ll u,v,w;
ll head[N*];
ll dis[N],num[N];
struct Node{
ll u,v,w,nex;
Node(){
}
Node(ll u,ll v,ll w,ll nex):u(u),v(v),w(w),nex(nex){}
}e[N*];
void init()
{
cnt = ;
memset(head,-,sizeof(head));
}
void add(ll u,ll v,ll w)
{
e[cnt].u=u;e[cnt].v=v;e[cnt].w=w;
e[cnt].nex = head[u];head[u]=cnt++;
}
bool check(ll mid)
{
//假设在起点就已经更新了mid次,验证mid是否满足条件
priority_queue<P,vector<P>,greater<P> >q;
fill(dis,dis+n+,inf);fill(num,num+n+,inf);
dis[]=num[]=;
q.push(P(,));
while(!q.empty())
{
P tmp =q.top();q.pop();
ll u=tmp.second;
if(dis[u]<tmp.first) continue;
for(ll i=head[u];i!=-;i=e[i].nex){
ll v=e[i].v;
if(dis[v]>dis[u]+e[i].w&&e[i].w<=mid*d){
dis[v] = dis[u] +e[i].w;
num[v] = min(num[v],num[u]+);//更新出最小的
q.push(P(dis[v],v));
}
}
}
return num[n]<=mid*E;//1: 可以走到n 2 :走过的路径数目满足条件
}
int main()
{
init();
scanf("%d%d",&n,&m);
scanf("%lld%lld%lld",&c,&d,&E);
for(int i =;i<m;i++) {
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
ll l =,r=,res,mid;
while(l<=r)
{
mid = (l+r)>>;
if(check(mid)) {
res = mid;r=mid-;
}
else{
l=mid+;
}
}
printf("%lld\n",res*c);
return ;
}
    //code2
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define N 100100
#define inf 1e12
int n,m,cnt;
ll c,d,E;ll u,v,w;
ll head[N*];
bool vis[N];
struct Node{
ll u,v,w,nex;
Node(){
}
Node(ll u,ll v,ll w,ll nex):u(u),v(v),w(w),nex(nex){}
}e[N*];
void init()
{
cnt = ;
memset(head,-,sizeof(head));
}
void add(ll u,ll v,ll w)
{
e[cnt].u=u;e[cnt].v=v;e[cnt].w=w;
e[cnt].nex = head[u];head[u]=cnt++;
}
bool check(ll mid)
{
/*
由于是树,那么任意两点的路径唯一
只需要判断在 当前的次数下,在满足单次可飞行距离≥这条路的长度下,凭借的当前可用步数能走到n吗
*/
memset(vis,,sizeof(vis));//每次都是重新来
ll num =mid*E;ll dd = mid*d;
//假设在起点就已经更新了mid次,验证mid是否满足条件
queue<P>q ;
q.push(P(,num)); //first :当前 到达的点 second :还余下的可走的步数
vis[]=;
while(!q.empty())
{
P tmp =q.front();q.pop();
ll u = tmp.first;ll cnt=tmp.second;
if(u==n) return ;
else{
for(ll i=head[u];i!=-;i=e[i].nex){
ll v=e[i].v;
if(!vis[v]&&e[i].w<=dd&&cnt>){
vis[v] = ;
q.push(P(v,cnt-));
}
}
}
}
return ;
}
int main()
{
init();
scanf("%d%d",&n,&m);
scanf("%lld%lld%lld",&c,&d,&E);
for(int i =;i<m;i++) {
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
ll l =,r=,res,mid;
while(l<=r)
{
mid = (l+r)>>;
if(check(mid)) {
res = mid;r=mid-;
}
else{
l=mid+;
}
}
printf("%lld\n",res*c);
return ;
}

2019 西安邀请赛 M的更多相关文章

  1. 2019 西安邀请赛 D

    //n件物品,m种关系,(有关系的2个不能在同一组) //把所有物品分为2组,希望最后2组的差值尽可能小,输出较大者 /* 二分图涂色+可行性(01)背包 dp[i] =1表示 最后差值为i可行 建图 ...

  2. ACM-ICPC 2019 西安邀请赛 D.Miku and Generals(二分图+可行性背包)

    “Miku is matchless in the world!” As everyone knows, Nakano Miku is interested in Japanese generals, ...

  3. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  4. 2019南昌邀请赛网络预选赛 M. Subsequence

    传送门 题意: 给出一个只包含小写字母的串 s 和n 个串t,判断t[i]是否为串 s 的子序列: 如果是,输出"YES",反之,输出"NO": 坑点: 二分一 ...

  5. 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛

    Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...

  6. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

  7. 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛

    Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on ...

  8. 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛

    Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...

  9. The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And

    链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...

随机推荐

  1. numpy函数库中一些常用函数的记录

    ##numpy函数库中一些常用函数的记录 最近才开始接触Python,python中为我们提供了大量的库,不太熟悉,因此在<机器学习实战>的学习中,对遇到的一些函数的用法进行记录. (1) ...

  2. mssql 清理死锁

    -存储过程 我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和SQL语句.SQL Server自带的系统存储过程sp_who和sp_lock也可以用来查找阻塞和死锁, 但没有这里介绍的方法好用 ...

  3. 02-Flutter移动电商实战-建立项目和编写入口文件

    环境搭建请参考之前写的一篇文章:Flutter_初体验_创建第一个应用 1.创建项目 采用AndroidStudio构建本项目,FIle>New>New Flutter Project… ...

  4. Expectation Maximization Algorithm

    期望最大化算法EM. 简介 EM算法即期望最大化算法,由Dempster等人在1976年提出[1].这是一种迭代法,用于求解含有隐变量的最大似然估计.最大后验概率估计问题.至于什么是隐变量,在后面会详 ...

  5. Linux下搭建iSCSI共享存储的方法 Linux-IO Target 方式CentOS7-1810下实现

    iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速 ...

  6. 洛谷P4380 [USACO18OPEN]Multiplayer Moo

    题目 第一问: 用广搜类似用\(floodfill\)的方法. 第二问: 暴力枚举加剪枝,对于每个连通块,枚举跟这个连通块相连的其他与他颜色不同的连通块,然后向外扩展合并颜色与他们俩相同的连通块.扩展 ...

  7. GoCN每日新闻(2019-10-09)

    GoCN每日新闻(2019-10-09) GoCN每日新闻(2019-10-09) 1. 我们如何将服务延迟减少了98% https://blog.gojekengineering.com/the-n ...

  8. Windows安装Python3 curses模块

    目录 0.前提 1.pip install wheel 2.下载.whl文件 3.pip install 它 参考 0.前提 确定你已经配置好了Python相关环境,可以正常在命令行使用pip安装. ...

  9. Web前端开发规范之图片命名规范

    图片的名称分为头尾两部分,用下划线隔开,头部表示此图片的大类性质,例如广告,标志,菜单,按钮等 banner:放置在页面顶部的广告,装饰图案等长方形的图片 logo:标志性的图片 button:在页面 ...

  10. HTTP APIs 设计/规范指南

    根据REST APIs的成熟度模型 ,此规范关注的是Level 2的APIs.  1 设计指南 HTTP APIs主要由四部分组成:HTTP,URL,资源,资源的表述(JSON).资源的表述格式通常都 ...