Problem I

Interesting Calculator

There is an interesting calculator. It has 3 rows of button.

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 256
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
12 256
100 100 100 1 100 100 100 100 100 100
100 100 100 100 100 1 100 100 100 100
100 100 10 100 100 100 100 100 100 100

Output for the Sample Input

Case 1: 2 2
Case 2: 12 3

The Ninth Hunan Collegiate Programming Contest (2013)
Problemsetter: Rujia Liu
Special Thanks: Feng Chen, Md. Mahbubul Hasan

  典型的广搜,有最优性,用堆来优化可以加速运行,这种试题本质很老,需要认识本质,找准突破口。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const LL inf=(LL) ;
int num[][] ;
LL dist[] ;
LL step[] ;
int x, y;
struct Node{
int Num ;
LL money ;
LL Step ;
Node(){} ;
Node(int n ,LL m ,LL s):Num(n),money(m),Step(s){} ;
friend bool operator <(const Node A ,const Node B){
if(A.money==B.money)
return A.Step>B.Step ;
else
return A.money>B.money ;
}
};
void bfs(){
priority_queue<Node>que ;
fill(step,step+y+,inf) ;
fill(dist,dist+y+,inf) ;
que.push(Node(x,,)) ;
dist[x]= ;
step[x]= ;
while(!que.empty()){
Node now=que.top() ;
que.pop() ;
if(now.Num==y){
return ;
}
int next_id ;
for(int k=;k<=;k++){ for(int i=;i<=;i++){
if(k==)
next_id=now.Num*+i ;
else if(k==)
next_id=now.Num+i ;
else if(k==)
next_id=now.Num*i ;
if(next_id>y)
continue ;
if(now.money+num[k][i]<dist[next_id]){
dist[next_id]=now.money+num[k][i] ;
step[next_id]=now.Step+ ;
que.push(Node(next_id,dist[next_id],step[next_id])) ;
}
else if(now.money+num[k][i]==dist[next_id]){
if(now.Step+<step[next_id]){
step[next_id]=now.Step+ ;
que.push(Node(next_id,dist[next_id],step[next_id])) ;
}
}
} } }
}
int main(){
int k= ;
while(scanf("%d%d",&x,&y)!=EOF){
for(int i=;i<=;i++)
for(int j=;j<=;j++)
scanf("%d",&num[i][j]) ;
bfs() ;
printf("Case %d: ",k++) ;
cout<<dist[y]<<" "<<step[y]<<endl ;
}
return ;
}

The Ninth Hunan Collegiate Programming Contest (2013) Problem I的更多相关文章

  1. The Ninth Hunan Collegiate Programming Contest (2013) Problem A

    Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...

  2. The Ninth Hunan Collegiate Programming Contest (2013) Problem F

    Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...

  3. The Ninth Hunan Collegiate Programming Contest (2013) Problem H

    Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  6. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

  8. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

  9. German Collegiate Programming Contest 2013:B

    一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...

随机推荐

  1. ajax简单案例:返回json型

    主页: <!--输入代号点击查询查到本代号的人名--> <body> <div> 请输入代号:<input type="text" id= ...

  2. [原]在Fedora 20环境下安装系统内核源代码

    1.安装Kernel Headers(头文件) 通过安装kernel-devel RPM包就可以得到Kernel Headers,但默认情况下没有被Fedora 20安装.通过DVD ISO 或者 y ...

  3. ICSharpCode.SharpZipLib.dll,MyZip.dll,Ionic.Zip.dll 使用

    MyZip.dll : 有BUG,会把子目录的文件解压到根目录.. ICSharpCode.SharpZipLib.dll: 把ICSharpCode.SharpZipLib.dll复制一份,重命名为 ...

  4. POJ #1015 - Jury Compromise - TODO: POJ website issue

    (poj.org issue. Not submitted yet) This is a 2D DP problem, very classic too. Since I'm just learnin ...

  5. 战胜忧虑<2>——忙碌可以消除忧虑

    忙碌可以消除忧虑 当你的脑筋空出来时,也会有东西进去补充,是什么呢?通常都是你的感觉.为什么?因为忧虑.恐惧.憎恨.嫉妒.和羡慕等等情绪,都是由我们的思想所控制的,这种情绪都非常猛烈.会把我们思想中所 ...

  6. android打印调用栈

    在某些机器上,不能下断点,出现了某个诡异的问题,想到唯一的解决方式,就是打印调用栈了,google发现这个,记录下,以后备用 Log.d(",Log.getStackTraceString( ...

  7. Windows 7 的系统文件修复:sfc /scannow

    在线检查与修复 C:\Windows\system32>sfc /scannow 开始系统扫描.此过程将需要一些时间. 开始系统扫描的验证阶段. 验证 100% 已完成. Windows 资源保 ...

  8. 【MySQL】索引长度的一些限制

    有同学问到InnoDB的索引长度问题,简单说几个tips. MySQL的每个单表中所创建的索引长度是有限制的,且对不同存储引擎下的表有不同的限制. myisam表,单列索引,最大长度不能超过 1000 ...

  9. (C#) 判断相等?

    值类型直接用 == 号判断就好. 但是对于引用类型,需要实现IComparable 接口,或者重写 Equal 方法,来实现自己的比较目的. 因为对于引用类型,==号比较的是入口地址,对于同一个cla ...

  10. OAF_MDS系列1_OAF页面元数据结构MDS的解析(概念)

    2014-06-06 Created By BaoXinjian