CSU~1336: Interesting Calculator(spfa)
来源:互联网 发布:stc89c52单片机驱动 编辑:程序博客网 时间:2024/06/07 07:36
1336: Interesting Calculator
Time Limit: 2 Sec Memory Limit: 128 Mb Submitted: 755 Solved: 184Description
There is an interesting calculator. It has 3 rows of buttons.
Row 1: button 0, 1, 2, 3, ..., 9. Pressing each button appends that digit to the end of the display.
Row 2: button +0, +1, +2, +3, ..., +9. Pressing each button adds that digit to the display.
Row 3: button *0, *1, *2, *3, ..., *9. Pressing each button multiplies that digit to the display.
Note that it never displays leading zeros, so if the current display is 0, pressing 5 makes it 5 instead of 05. If the current display is 12, you can press button 3, +5, *2 to get 256. Similarly, to change the display from 0 to 1, you can press 1 or +1 (but not both!).
Each button has a positive cost, your task is to change the display from x to y with minimum cost. If there are multiple ways to do so, the number of presses should be minimized.
Input
There will be at most 30 test cases. The first line of each test case contains two integers x and y(0<=x<=y<=105). Each of the 3 lines contains 10 positive integers (not greater than 105), i.e. the costs of each button.
Output
For each test case, print the minimal cost and the number of presses.
Sample Input
12 2561 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 112 256100 100 100 1 100 100 100 100 100 100100 100 100 100 100 1 100 100 100 100100 100 10 100 100 100 100 100 100 100
Sample Output
Case 1: 2 2Case 2: 12 3
Hint
Source
湖南省第九届大学生计算机程序设计竞赛#include <iostream>#include<string>#include<string.h>#include<stdio.h>#include<stdlib.h>#include<queue>#include<math.h>#include<algorithm>#define ll long long#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define maxn 100000+5using namespace std;int c[3][10],st,ed;int dis[maxn],num[maxn];int vis[maxn];int Case=1;void spfa(){ mem(dis,inf); mem(vis,0); queue<int>q; int u,v,t; q.push(st); vis[st]=1; num[st]=dis[st]=0; while(!q.empty()) { u=q.front(); q.pop(); vis[u]=0; for(int i=0;i<3;i++) { for(int j=0;j<10;j++) { if(i==0) v=u*10+j; else if(i==1) v=u+j; else v=u*j; if(v>ed)continue; if(dis[v]>dis[u]+c[i][j]) { dis[v]=dis[u]+c[i][j]; num[v]=num[u]+1; if(!vis[v]) { vis[v]=1; q.push(v); } } } } } printf("Case %d: %d %d\n",Case++,dis[ed],num[ed]);}int main(){ while(~scanf("%d%d",&st,&ed)) { for(int i=0;i<3;i++) { for(int j=0;j<10;j++) { scanf("%d",&c[i][j]); } } spfa(); } return 0;}
- CSU~1336: Interesting Calculator(spfa)
- CSU 1336 Interesting Calculator(spfa)
- CSU-1336--Interesting Calculator(bfs)
- CSU-1336: Interesting Calculator,最短路思想!
- Interesting Calculator CSU
- CSUOJ 1336 Interesting Calculator spfa / 优先队列
- CSUOJ 1336 Interesting Calculator (spfa算法)
- CSU 1336: Interesting Calculator<BFS+优化><湖南省赛真题>
- TOJ 4603 Interesting Calculator -- SPFA
- UVA 12664 Interesting Calculator(spfa)
- CSU 1336: Interesting Calculator(BFS啊 湖南省第九届大学生计算机程序设计竞赛)
- Interesting Calculator
- Interesting Calculator
- CSUOJ 1336 Interesting Calculator(BFS+优先队列)
- UVA 12664 Interesting Calculator
- Interesting Calculator UVA
- Interesting Calculator UVA
- Interesting Calculator UVA
- Codeforces Round #370 (Div. 2) D. Memory and Scores —— DP
- ViewDragHelper 深入解析
- 单例模式中为什么用枚举更好?
- 关于web前端学习
- 斯坦福 cs106A Assignment4
- CSU~1336: Interesting Calculator(spfa)
- SVN有冲突
- vs2015加载项目失败
- 字符、字节、字符集的小疑问
- php get_magic_quotes_gpc()函数用法介绍(防注入)
- 单词查找树
- 网路编程(二)UDP和TCP协议下传输数据
- mac上编译安装lnmp环境(php7.0)
- 流水作业调度问题