湖南省第九届大学生计算机程序设计竞赛 Interesting Calculator
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的更多相关文章
- CSUOJ1329——一行盒子_湖南省第九届大学生计算机程序设计竞赛
题目是中文的我就不是说明了,比赛的时候看过题目后队友说是splay来做,细想来省赛不会出这么坑的题目吧. 于是比赛还有一个小时左右把该做的都做完了以后,我们队三个人都来思考这个题目了.不过还好很快我们 ...
- 湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心
2007: Football Training Camp[原创-转载请说明] Submit Page Summary Time Limit: 1 Sec Memory Limit: 1 ...
- 2018湖南省第14届大学生计算机程序设计竞赛 D: 卖萌表情
Description 已知以下 4 种都是卖萌表情(空白的部分可以是任意字符.竖线是便于展示的分隔符,没有实际意义): ^ ^ | ^ | < | > v | v v | > | ...
- 2018湖南省第14届大学生计算机程序设计竞赛 C: 时间旅行
Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中. 当 Bobo 位于时间轴上 t 点,同时时间机器有 c 单位燃料时,他可以选择一个 ...
- 2018湖南省第14届大学生计算机程序设计竞赛 A字符画
Description 读入 w,请输出 2018 的字符画,两个数字之间有 w 个空格.具体格式请参考样例输出. 1 ≤ w ≤ 2018 Input 输入文件只包含 1 个整数 w. Output ...
- 希尔加密算法(湖南师范大学第六届大学生计算机程序设计竞赛)hnuoj11552
解密 Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 2, Accept ...
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- csu 1503: 点弧之间的距离-湖南省第十届大学生计算机程序设计大赛
这是--比量p并用交点连接中心不上弧.在于:它至p距离.是不是p与端点之间的最短距离 #include<iostream> #include<map> #include< ...
- 2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解
2019年湖南省大学生计算机程序设计竞赛 (HNCPC2019) 简要题解 update10.01 突然发现叉姐把这场的题传到牛客上了,现在大家可以有地方提交了呢. 不知道该干什么所以就来水一篇题解 ...
随机推荐
- svn 版本库信息修改
root@hpcstack hpcweb]# svn info 路径: . URL: http://svn.pyindex.com/hpcweb 版本库根: http://svn.pyindex.co ...
- OBJECTPROPERTY用法整理
OBJECTPROPERTY用法整理 分类: 系统表与表结构 数据库管理维护2010-06-03 16:37 2783人阅读 评论(1) 收藏 举报 数据库sql serverinsertobject ...
- 在计算机中简单的hello程序的运行
我之前很好奇就是你所写的代码到底是如何在计算机中执行的,到底是怎样开始,从哪里开始,在哪里执行,到哪里结束,之间到底是怎么的一个过程,带着这些问题,逐渐看这方面的书籍,最近买的<深入理解计算机系 ...
- 常量指针(pointer to constant)和指针常量(constant pointer)
一个指针可以操作两个实体,一个是指针值(即地址),一个是间访值(即指向的实体).于是指针的常量性也分为两种:常量指针(pointer to constant)和指针常量(constant pointe ...
- Layui框架 中table解决日期格式问题
使用templet自定义模板(详细查看官方文https://www.layui.com) 1.对Date的扩展,将 Date 转化为指定格式的String ,创建一个js文件: (dataForma ...
- org.dom4j.DocumentException
在使用soapui测试webservice接口的时候如果需要传入xml格式的参数 这么写是不对的,会报错org.dom4j.DocumentException: Error on line 1 of ...
- Linux系统用户、组和权限管理
一.用户与组 1.用户与组的概念 在linux系统中,根据系统管理需要将用户分为三种类型: 1.超级用户:root是linux系统的超级用户,对系统拥有绝对权限.由于root用户权限太大,只有在进行系 ...
- PHP经典算法集锦【经典收藏】
本文实例总结了PHP经典算法.分享给大家供大家参考,具体如下: 1.首先来画个菱形玩玩,很多人学C时在书上都画过,咱们用PHP画下,画了一半. 思路:多少行for一次,然后在里面空格和星号for一次. ...
- Linux基础命令回顾
前言 说到linux基础命令,网上一搜一箩筐,想学也有很多教程,如果你不幸看到此篇文章,想看就认真看完,毕竟你点进来了不是嘛? 我每次写的文章都是为了分享自己的学习成果或重要知识点,希望能帮助更多的人 ...
- SpringBoot第十六篇:自定义starter
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/11058502.html 版权声明:本文为博主原创文章,转载请附上博文链接! 前言 这一段时间 ...