The Ninth Hunan Collegiate Programming Contest (2013) Problem I
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的更多相关文章
- 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 ...
- 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 ...
- 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. ...
- 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, ...
- 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 ...
- 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 ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
- German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
- German Collegiate Programming Contest 2013:B
一个离散化的简单题: 我用的是STL来做的离散化: 好久没写离散化了,纪念一下! 代码: #include<cstdio> #include<cstring> #include ...
随机推荐
- 淘宝PHPSDK2.0 剔除 lotusphp框架---兄弟连教程
淘宝PHPSDK2.0 剔除 lotusphp框架---兄弟连教程. lotusphp是一个国产开源的php框架 由于有个朋友公司是做淘宝客的,还由于不少朋友在开淘宝,于是有必要研究下.尽管个人认为微 ...
- js 日期时间比较
js时间日期比较 <script type="text/javascript"> //begin > end 返回True function comptime(b ...
- 程序员书单_HTML篇
JavaScript权威指南(第六版) http://download.csdn.net/detail/shenzhq1980/9137733 改善JavaScript程序的188个建议 http:/ ...
- VS2013 启动时遇到空白窗口
安装了VS2013 ,然后打开,遇到空白窗口,等了10几秒无果. 我先是修复了VS2013,然后再打开VS2013,则显示登录微软账号的窗口.修复完2013时正好18:08,可能是下班了可以上网,才正 ...
- Chrome离线下载地址
每当chrome有更新之后,都有不少用户想要下载离线版的安装文件,但苦于找不到下载地址而发愁,其实这个问题很简单,下面我来分享一下方法(仅针对Windows操作系统): 对于稳定版(正式版)Chrom ...
- 详解 “Android UI”设计官方教程
我们曾经给大家一个<MeeGo移动终端设备开发UI设计基础教程>,同时很多朋友都在寻找Android UI开发的教程,我们从Android的官方开发者博客找了一份幻灯片,介绍了一些Andr ...
- u-boot启动流程分析(2)_板级(board)部分
转自:http://www.wowotech.net/u-boot/boot_flow_2.html 目录: 1. 前言 2. Generic Board 3. _main 4. global dat ...
- C# is和as操作符
is和as操作符 is操作符:检查对象是否与给定类型兼容. 说明: 1.如果所提供的表达式非空,并且所提供的对象可以强制转换为所提供的类型而不会导致引发异常,则 is 表达式的计算结果将是 true, ...
- wordpress主题结构_源码
WordPress博客主题的工作机制 WordPress主题由一系列模板文件组成,每个文件分别控制主题的特定区域.无论你处于哪个页面都能看到的网站的静态部分,由header文件.sidebar和foo ...
- contentProvider 内容提供者
http://blog.csdn.net/woshixuye/article/details/8280879 实例代码当数据需要在应用程序间共享时,我们就可以利用ContentProvider为数据定 ...