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. 设计师必看的10个HTML5动画工具

    如果你想用令人难以置信的动画创建引人注目的网站的话,那么这里为设计师精心挑选了一些必备的HTML5动画工具.HTML5是设计师用来打造时尚网站的最流行的编程语言之一.在过去三年内,这种编程语言的使用人 ...

  2. LintCode "The Smallest Difference"

    Binary search. class Solution { int _findClosest(vector<int> &A, int v) { , e = A.size() - ...

  3. 【Redis】配置redis主从复制

    阅读目录 redis-3.2.1.master tar zxvf redis-3.2.1.tar.gz mv redis-3.2.1 redis-3.2.1.slave-1 tar zxvf redi ...

  4. 【Spring学习笔记-1】Myeclipse下Spring环境搭建

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  5. linux时间管理

    /etc/sysconfig/clock         该配置文件可用来设置用户选择何种方式显示时间.如果硬件时钟为本地时间,则UTC设为0,并且不用设置环境变量TZ.如果硬件时钟为UTC时间,则要 ...

  6. ab压测参数说明

    ab是apache自带的压力测试工具,非常实用.ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问.它的测试目标是基于URL的,因此,它既可以用来测试apache的负载压力,也 ...

  7. ADB工具 获取ROOT权限及复制文件方法

    adb push d:\tm3_sqlit.db data/zouhao/tm3_sqlit.dbadb pull data/zouhao/tm3_sqlit.db d:\tm3_sqlit.db a ...

  8. gcc和ld 中的参数 --whole-archive 和 --no-whole-archive

    首先 --whole-archive 和 --no-whole-archive 是ld专有的命令行参数,gcc 并不认识,要通gcc传递到 ld,需要在他们前面加 -Wl,字串. --whole-ar ...

  9. 关于mac mini组装普液晶显示器

    申请了好久的mac mini,部门终于给买下来了.没想到,买回来之后的组装还是折腾了我们一把.  因为先前没用过mac mini,以为它和普通的台式机一样,买回来就能直接到显示器上用了.结果买回来ma ...

  10. 洛谷 P1060 开心的金明

    开心的金明 Problem Description: 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:"你的房间需要购买哪些 ...