湖南省第九届大学生计算机程序设计竞赛 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 突然发现叉姐把这场的题传到牛客上了,现在大家可以有地方提交了呢. 不知道该干什么所以就来水一篇题解 ...
随机推荐
- Hadoop架构模型
1.hadoop 1.x架构模型:分布式文件存储系统:HDFSNameNode(主节点:管理元数据) secondaryNameNode(作用是合并元数据信息,辅助NameNode管理元数据信息)Da ...
- 用node写个简单的静态服务器
直接上代码吧,我把它命名为 app.js, 只要在该文件所在目录下,控制台运行 node app.js 即可启动一个本地服务器了. /** * 服务器 * Author jervy * Date */ ...
- NOIP专题复习1 图论-最短路
一.知识概述 今天我们要复习的内容是图论中的最短路算法,我们在这里讲3种最短路求法,分别是:floyd,dijkstra,spfa. 那么我们从几道例题来切入今天讲解的算法. 二.典型例题 1.热浪 ...
- python多线程和多进程(一)
一.多线程 Python的标准库提供了两个模块:_thread和threading,_thread是低级模块,threading是高级模块,对_thread进行了封装.绝大多数情况下,只需要使用thr ...
- Yum:更换aliyun的yum源
备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup centos7 wget -O /et ...
- python之字典 2014-4-5
#字典:当索引不好用时1.字典 类似于php的关联数组 列表类似于索引数组 2.创建字典 phonebook={'alice':'2100','tom':'1900'} 键值之间用: 项之间用, 空字 ...
- BNUOJ 6023 畅通工程续
畅通工程续 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 1874 ...
- Mongo的Replica Sets (复制集)的配置全过程和心得体会
http://blog.csdn.net/bloggongchang/article/details/7272403 一.MongoDB Replica Sets(副本集)简单的说就是有自动故障恢复功 ...
- SQL Server 2008如何创建定期自动备份任务
我们知道,利用SQL Server 2008数据库可以实现数据库的定期自动备份.方法是用SQL SERVER 2008自带的维护计划创建一个计划对数据库进行备份,下面我们将SQL SERVER 200 ...
- [NOIP2007] 提高组 洛谷P1099 树网的核
题目描述 设T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边到有正整数的权,我们称T为树网(treebetwork),其中V,E分别表示结点与边的集合,W表示各边长度的集合,并 ...