当前位置:网站首页>7-9 超级玛丽
7-9 超级玛丽
2022-06-22 20:24:00 【白—】
7-9 超级玛丽
假定有n个城堡,编号为1至n,有的城堡之间有道路直接相连,有的城堡之间没有道路直接相连。马里奥现在准备从一个城堡出发前往另一个城堡,它有一个魔法棒,可以瞬时通过一条道路,即以0时间通过这条道路,但魔法棒最多只能用一次。马里奥想以最短的时间到达目的地,请编写程序为马里奥选定一条路线以及在什么地方使用魔法棒。假定所有道路为双向,保证从起点肯定能到达目的地。
输入格式:
输入第一行为4个整数n、s、t、m,分别表示城堡数(编号为1至n,n不超过10000),马里奥所在的起点s和想去的终点t,城堡间的道路数目。接下来m行,每行为3个正整数a、b、c,表示城堡a和城堡b之间有一条道路直接相连,通过该道路需要c分钟。
输出格式:
输出为空格间隔的2个整数,第1个整数为马里奥从起点到目的地所需的最短时间;第2个整数表示使用魔法棒的地点,即城堡编号,若有多个可能的地点,则输出编号最小者。
输入样例:
4 1 4 4
1 2 9
2 4 1
1 3 3
3 4 5
输出样例:
1 1
一直有个点错。。。不晓得哪错了,只有7分
代码:
#include <iostream>
using namespace std;
int n,s,t,m;
int a[20001][20001];
int vis[20001];
int tempnumber=1e8,tempmax=-111111,tempminn;///暂时
int remnumber=1e8,remminn=1e8;;///实际
void dfs(int x)
{
if(tempminn-tempmax>remminn)///剪枝
return;
if(x==t)
{
if(tempminn-tempmax<remminn)
{
remminn=tempminn-tempmax;
remnumber=tempnumber;
}
else if(tempminn-tempmax==remminn&&tempnumber<remnumber)
{
remminn=tempminn-tempmax;
remnumber=tempnumber;
}
return;
}
for(int i=1;i<=n;i++)
{
if(!vis[i]&&a[x][i])
{
int temp1=tempmax,temp2=tempnumber;
vis[i]=1;
if(a[x][i]>tempmax)
{
tempmax=a[x][i];
tempnumber=x;
}
else if(a[x][i]==tempmax)
{
tempmax=a[x][i];
tempnumber=min(tempnumber,x);
}
tempminn+=a[x][i];
dfs(i);
vis[i]=0;
tempmax=temp1;
tempnumber=temp2;
tempminn-=a[x][i];
}
}
}
int main()
{
cin>>n>>s>>t>>m;///分别表示城堡数,起点s,终点t,道路数目
int q,b,c;
for(int i=0;i<m;i++)
{
cin>>q>>b>>c;
a[q][b]=a[b][q]=c;
}
vis[s]=1;
dfs(s);
cout<<remminn<<' '<<remnumber;
return 0;
}
202206201626一
边栏推荐
- What is a data asset? How should data asset management be implemented?
- Lesson 028: Documents: because I know you, I will never forget the after-school test questions and answers [no title]
- 杰理之使用 DP 和 DM 做 IO 按键检测注意点【篇】
- kali2021安装RTL8188GU无线网卡[TL-WN726N]驱动
- 《跟唐老师学习云网络》 - OpenStack网络实现
- RuntimeError: CUDA error: CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemmStridedBatched( ha
- Learning cloud network from teacher Tang - openstack network implementation
- DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]
- 万字长文 | 使用 RBAC 限制对 Kubernetes 资源的访问
- The problem that Jericho can't play the prompt tone in the music mode using the interrupt mode [chapter]
猜你喜欢
![Jerry's near end tone change problem of opening four channel call [chapter]](/img/03/f08cd660c1c602aa08218c4c791ec3.png)
Jerry's near end tone change problem of opening four channel call [chapter]

第033讲:异常处理:你不可能总是对的2 | 课后测试题及答案

IDC發布中國數據治理報告 億信華辰第一

科研热点|官宣!2022年JCR分区和影响因子发布时间确定!

软考必备资料大放送,全科目软考资料都给你备好了!

What is a data asset? How should data asset management be implemented?

杰理之MUSIC 模式获取播放文件的目录【篇】

Lesson 029: Documents: a task? After class test questions and answers
![[records of different objects required by QIPA]](/img/f7/c0f0f56e4f1bf4f1a0a61552afcd2b.png)
[records of different objects required by QIPA]

Lesson 033: exception handling: you can't always be right 2 | after class test questions and answers
随机推荐
《跟唐老师学习云网络》 - OpenStack网络实现
One line of code binds swiftui view animation for a specific state
When the AUX1 or aux2 channel is used in Jerry's aux mode, the program will reset the problem [chapter]
Adblock屏蔽百度热搜
Android kotlin SP DP to PX
杰理之硬件上 DACL 输出,DAC 输出左右声道的声音【篇】
Microsoft edge browser will support network speed measurement, built-in calculator and unit conversion tool
第019讲:函数:我的地盘听我的 | 课后测试题及答案
[redis] publish and subscribe
【ICML2022】利用虚拟节点促进图结构学习
什么是数据资产?数据资产管理应该如何落地?
第023、024讲:递归:这帮小兔崽子、汉诺塔 | 课后测试题及答案
85- have you learned any of these SQL tuning tips?
90- review of several recently optimized Oracle databases
IDC发布中国数据治理报告 亿信华辰第一
Operation of simulation test platform for 2022 Shandong safety officer C certificate test
Lesson 019: function: my site listen to my after-school test questions and answers
大势智慧创建倾斜模型和切割单体化
软考必备资料大放送,全科目软考资料都给你备好了!
解决phpstudy中mysql无法启动,与本地安装的mysql冲突