HDU 4114 Disney's FastPass Time

本文探讨了迪士尼乐园中FastPass系统的运作原理及其背后的算法实现。该系统通过虚拟排队方式帮助游客有效安排游玩时间,避免长时间等待。文章详细介绍了算法的具体实现过程,包括输入输出格式、样例解释等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Disney's FastPass

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2403    Accepted Submission(s): 658

Problem Description
Disney's FastPass is a virtual queuing system created by the Walt Disney Company. First introduced in 1999 (thugh the idea of a ride reservation system was first introduced in world fairs), Fast-Pass allows guests to avoid long lines at the attractions on which the system is installed, freeing them to enjoy other attractions during their wait. The service is available at no additional charge to all park guests.
--- wikipedia



Disneyland is a large theme park with plenties of entertainment facilities, also with a large number of tourists. Normally, you need to wait for a long time before geting the chance to enjoy any of the attractions. The FastPass is a system allowing you to pick up FastPass-tickets in some specific position, and use them at the corresponding facility to avoid long lines. With the help of the FastPass System, one can arrange his/her trip more efficiently.
You are given the map of the whole park, and there are some attractions that you are interested in. How to visit all the interested attractions within the shortest time?
 
Input
The first line contains an integer T(1<=T<=25), indicating the number of test cases.
Each test case contains several lines.
The first line contains three integers N,M,K(1 <= N <= 50; 0 <= M <= N(N - 1)/2; 0 <= K <= 8), indicating the number of locations(starting with 1, and 1 is the only gate of the park where the trip must be started and ended), the number of roads and the number of interested attractions.
The following M lines each contains three integers A,B,D(1 <= A,B <= N; 0 <= D <= 10^4) which means it takes D minutes to travel between location A and location B.
The following K lines each contains several integers Pi, Ti, FTi,Ni, Fi,1, Fi,2 ... Fi,Ni-1, FiNi ,(1 <= Pi,Ni, Fi,j <=N, 0 <= FTi <= Ti <= 10^4), which means the ith interested araction is placed at location Pi and there are Ni locations Fi,1; Fi,2 ... Fi,Ni where you can get the FastPass for the ith attraction. If you come to the ith attraction with its FastPass, you need to wait for only FTi minutes, otherwise you need to wait for Ti minutes.
You can assume that all the locations are connected and there is at most one road between any two locations.
Note that there might be several attrractions at one location.
 
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is the minimum time of the trip.
 
Sample Input
2
4 5 2
1 2 8
2 3 4
3 4 19
4 1 6
2 4 7
2 25 18 1 3
4 12 6 1 3
4 6 2
1 2 5
1 4 4
3 1 1
3 2 1
3 4 1
2 4 10
2 8 3 1 4
4 8 3 1 2
 
Sample Output
Case #1: 53
Case #2: 14
 
  1 #include <iostream>
  2 #include <cstring>
  3 #define N 55
  4 #define inf 0x3fffffff
  5 using namespace std;
  6 int mapp[N][N];
  7 bool vis[N];
  8 int T[N],FT[N],Pass[N],pos[N];
  9 int dis[N][1<<8][1<<8];
 10 int n,m,kk;
 11 void floyd(){
 12     for(int k=1;k<=n;k++){
 13         for(int i=1;i<=n;i++){
 14             if(i==k){
 15                 continue;
 16             }
 17             for(int j=1;j<=n;j++){
 18                 if(j==i||j==k){
 19                     continue;
 20                 }
 21                 mapp[i][j]=min(mapp[i][k]+mapp[k][j],mapp[i][j]);
 22             }
 23         }
 24     }
 25 }
 26 
 27 void init(){
 28     for(int i=1;i<=n;i++){
 29         for(int j=1;j<=n;j++){
 30             mapp[i][j]=inf;
 31         }
 32         mapp[i][i]=0;
 33         for(int j=0;j<(1<<kk);j++){
 34             for(int k=0;k<(1<<kk);k++){
 35                 dis[i][j][k]=inf;
 36             }
 37         }
 38     }
 39     memset(Pass,0,sizeof(Pass));
 40 }
 41 
 42 int solve(){
 43     int ans=inf;
 44     dis[1][0][0]=0;
 45     for(int s1=0;s1<(1<<kk);s1++){
 46         for(int s2=0;s2<(1<<kk);s2++){
 47             for(int i=1;i<=n;i++){
 48                 int now = dis[i][s1][s2];
 49                 if(now==inf){
 50                     continue;
 51                 }
 52                 if(s2==((1<<kk)-1)){
 53                     ans=min(ans,now+mapp[i][1]);
 54                 }
 55                 for(int j=0;j<kk;j++){
 56                     if((s2&(1<<j))==0){
 57                         int &nxt=dis[pos[j]][s1|Pass[pos[j]]][s2^(1<<j)];
 58                         int add=mapp[i][pos[j]];
 59                         if(s1&(1<<j)){
 60                             add+=FT[j];
 61                         }
 62                         else{
 63                             add+=T[j];
 64                         }
 65                         nxt=min(nxt,now+add);
 66                     }
 67                 }
 68                 for(int j=1;j<=n;j++){
 69                     int &nxt=dis[j][s1|Pass[j]][s2];
 70                     int add=mapp[i][j];
 71                     nxt=min(nxt,now+add);
 72                 }
 73             }
 74         }
 75     }
 76     return ans;
 77 }
 78 
 79 int main(int argc, char const *argv[]){
 80     cin.sync_with_stdio(false);
 81     int TT,Case;
 82     int a,b,c;
 83     cin>>TT;
 84     for(Case=1;Case<=TT;Case++){
 85         cin>>n>>m>>kk;
 86         init();
 87         for(int i=0;i<m;i++){
 88             cin>>a>>b>>c;
 89             mapp[a][b]=c;
 90             mapp[b][a]=c;
 91         }
 92         floyd();
 93         for(int i=0;i<kk;i++){
 94             cin>>pos[i]>>T[i]>>FT[i];
 95             cin>>m;
 96             for(int j=0;j<m;j++){
 97                 int num;
 98                 cin>>num;
 99                 Pass[num]|=(1<<i);
100             }
101         }
102         cout<<"Case #"<<Case<<": "<<solve()<<endl;
103     }
104     return 0;
105 }
2017-01-30 17:57:06

转载于:https://www.cnblogs.com/xjh-shin/articles/6358224.html

内容概要:本文档详细介绍了一个基于MATLAB实现的跨尺度注意力机制(CSA)结合Transformer编码器的多变量时间序列预测项目。项目旨在精准捕捉多尺度时间序列特征,提升多变量时间序列的预测性能,降低模型计算复杂度与训练时间,增强模型的解释性和可视化能力。通过跨尺度注意力机制,模型可以同时捕获局部细节和全局趋势,显著提升预测精度和泛化能力。文档还探讨了项目面临的挑战,如多尺度特征融合、多变量复杂依赖关系、计算资源瓶颈等问题,并提出了相应的解决方案。此外,项目模型架构包括跨尺度注意力机制模块、Transformer编码器层和输出预测层,文档最后提供了部分MATLAB代码示例。 适合人群:具备一定编程基础,尤其是熟悉MATLAB和深度学习的科研人员、工程师和研究生。 使用场景及目标:①需要处理多变量、多尺度时间序列数据的研究和应用场景,如金融市场分析、气象预测、工业设备监控、交通流量预测等;②希望深入了解跨尺度注意力机制和Transformer编码器在时间序列预测中的应用;③希望通过MATLAB实现高效的多变量时间序列预测模型,提升预测精度和模型解释性。 其他说明:此项目不仅提供了一种新的技术路径来处理复杂的时间序列数据,还推动了多领域多变量时间序列应用的创新。文档中的代码示例和详细的模型描述有助于读者快速理解和复现该项目,促进学术和技术交流。建议读者在实践中结合自己的数据集进行调试和优化,以达到最佳的预测效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值