Interesting Calculator

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 163  Solved: 49

Description

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 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

Sample Output



Case 1: 2 2

Case 2: 12 3

AC代码例如以下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define M 10010
using namespace std; struct H
{
friend bool operator <(const H x,const H y)
{
return x.a>y.a||(x.a==y.a&&x.b>y.b);
}
int a,b,c; }; int cas=0;
int n,m;
int r1[10],r2[10],r3[10];
int vis[100005]; void bfs()
{
int i,j;
H aa,bb,cc;
priority_queue<H> q;
aa.c=n;
aa.a=0;
aa.b=0;
q.push(aa);
while(!q.empty())
{
bb=q.top();
q.pop();
if(vis[bb.c])
continue;
vis[bb.c]=1;
if(bb.c==m)
{
printf("Case %d: %d %d\n",cas,bb.a,bb.b);
return;
}
for(i=0;i<10;i++)
{
cc.c=bb.c*10+i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r1[i];
q.push(cc);
}
cc.c=bb.c+i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r2[i];
q.push(cc);
}
cc.c=bb.c*i;
if(cc.c>=0&&cc.c<100001&&!vis[cc.c])
{
cc.b=bb.b+1;
cc.a=bb.a+r3[i];
q.push(cc);
}
}
}
} int main()
{
int i,j;
while(~scanf("%d%d",&n,&m))
{
cas++;
for(i=0;i<10;i++)
scanf("%d",&r1[i]);
for(i=0;i<10;i++)
scanf("%d",&r2[i]);
for(i=0;i<10;i++)
scanf("%d",&r3[i]);
memset(vis,0,sizeof vis); bfs();
}
return 0;
}

湖南省第九届大学生计算机程序设计竞赛 Interesting Calculator的更多相关文章

  1. CSUOJ1329——一行盒子_湖南省第九届大学生计算机程序设计竞赛

    题目是中文的我就不是说明了,比赛的时候看过题目后队友说是splay来做,细想来省赛不会出这么坑的题目吧. 于是比赛还有一个小时左右把该做的都做完了以后,我们队三个人都来思考这个题目了.不过还好很快我们 ...

  2. 湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

    2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 1 ...

  3. 2018湖南省第14届大学生计算机程序设计竞赛 D: 卖萌表情

    Description 已知以下 4 种都是卖萌表情(空白的部分可以是任意字符.竖线是便于展示的分隔符,没有实际意义): ^ ^ | ^ | < | > v | v v | > | ...

  4. 2018湖南省第14届大学生计算机程序设计竞赛 C: 时间旅行

    Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中. 当 Bobo 位于时间轴上 t 点,同时时间机器有 c 单位燃料时,他可以选择一个 ...

  5. 2018湖南省第14届大学生计算机程序设计竞赛 A字符画

    Description 读入 w,请输出 2018 的字符画,两个数字之间有 w 个空格.具体格式请参考样例输出. 1 ≤ w ≤ 2018 Input 输入文件只包含 1 个整数 w. Output ...

  6. 希尔加密算法(湖南师范大学第六届大学生计算机程序设计竞赛)hnuoj11552

    解密 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 2, Accept ...

  7. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  8. csu 1503: 点弧之间的距离-湖南省第十届大学生计算机程序设计大赛

    这是--比量p并用交点连接中心不上弧.在于:它至p距离.是不是p与端点之间的最短距离 #include<iostream> #include<map> #include< ...

  9. 2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解

    2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解 update10.01 突然发现叉姐把这场的题传到牛客上了,现在大家可以有地方提交了呢. 不知道该干什么所以就来水一篇题解 ...

随机推荐

  1. hdfs深入:08、hdfs的JavaAPI以及如何解决winutils的问题

    /** * 通过url注册的方式访问hdfs,了解,不会用到 * @throws Exception */ 以下为详细代码://1.注册hdfs的url,让java代码能识别hdfs的url形式URL ...

  2. 2018 CCPC 桂林站(upc复现赛)总结

    比赛一开始盯上了A题和G题,一个小时过去了还没有出题,心里有些乱.这时我看D题很多人过了,于是宝儿去看D题,说D题简单,转化成二进制暴力,于是就去做了.写的时候好像思路有点卡,WA了一发,后来马上发现 ...

  3. 笔试算法题(26):顺时针打印矩阵 & 求数组中数对差的最大值

    出题: 输入一个数字矩阵,要求从外向里顺时针打印每一个数字: 分析: 从外向里打印矩阵有多重方法实现,但最重要的是构建合适的状态机,这样才能控制多重不同的操作: 注意有四种打印模式(左右,上下,右左, ...

  4. PHP 数组使用之道

    本文首发于 PHP 数组使用之道,转载请注明出处. 这个教程我将通过一些实用的实例和最佳实践的方式列举出 PHP 中常用的数组函数.每个 PHP 工程师都应该掌握它们的使用方法,以及如何通过组合使用来 ...

  5. 早期创业,应该充分利用互联网产品和服务(从”皇包车”看一家全球中文车导服务平台如何选用ToB产品)

       前段时间,在搜索"皇包车"相关的资料,于是在IT桔子网站看到了"从'皇包车'看一家全球中文车导服务平台如何选用ToB产品"这篇文章.   我是非常的震撼! ...

  6. Java反射机制(Reflect)解析-----https://www.cnblogs.com/fzz9/p/7738381.html

    Java反射机制(Reflect)解析-----https://www.cnblogs.com/fzz9/p/7738381.html

  7. 九度oj 题目1438:最小公倍数

    题目1438:最小公倍数 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2451 解决:2057 题目描述: 给定两个正整数,计算这两个数的最小公倍数. 输入: 输入包含多组测试数据,每 ...

  8. 扫描局域网内所有主机和MAC地址的Shell脚本

    #!/bin/bash #author: InBi #date: 2011-08-16 #website: http://www.itwhy.org/2011/08-20/939.html ##### ...

  9. 状态压缩DP总结

    POJ1185 炮兵部队问题: 在平原上才能放置炮兵,每个炮兵的上下左右2格之内都不能出现别的炮兵 可以考虑在当前行放置炮兵它的右侧和下侧绝对不会出现炮兵即可,左侧和上侧就能省去考虑 明显的状态压缩d ...

  10. [luoguP1058] 立体图(超级大模拟(¬︿̫̿¬☆))

    传送门 看到题后整个人成了mengbier 但是仔细分析一下就很简单了,先确定好输出的图的长和宽. 然后从输入的矩形的左上角的最下面的开始填充,顺序是从下到上,从左到右,从后往前. 填充的时候直接覆盖 ...