HK

Problem:B

Time Limit:2000ms

Memory Limit:65535K

Description

yy is interested in numbers and yy numbers all of the day, Now yy give us the definition of the HK of a decimal number: if(0 <= x < 10)  HK(x) = x, else HK(bit[1]bit[2]..bit[nBit]) = HK(bit[1] + bit[2] +...+bit[nBit]), such as HK(2) = 2, HK(364) = HK(3 + 6 + 4) = HK(13) = HK(1 + 3) = HK(4) = 4. As you can see is easy to a decimal number X's HK(X),  but now yy want to know the smallest x such in the range of 1 to x (1 and x included, x >= 1)  that there exist n decimal numbers who's HK(x) = m.

Input

There are multi case end with EOF
Each case has two numbers n, m as described above (0 <= n < 10^10000, 1<= m <= 9)

Output

Every case print like this "Case #cas: k" k is the casenumber, k is the smallest x mod 1000000007. If there is no answer just let k = -1.

Sample Input

1 1
2 2
2 1

Sample Output

Case #1: 1
Case #2: 11
Case #3: 10

Hint

In the second case in the range of [1, 11] Only HK(2) and HK(11) equal 2 . So 11 is the smallest number
In the third case in the range of[1, 10] Only HK(1) and HK(10) equal 1. 10 is the smallest number

题意:如果(0 <= x < 10)  HK(x) = x, 否则 HK(bit[1]bit[2]..bit[nBit]) = HK(bit[1] + bit[2] +...+bit[nBit]),
   例如 HK(2) = 2, HK(364) = HK(3 + 6 + 4) = HK(13) = HK(1 + 3) = HK(4) = 4.
   给定n和m,就是求第n个和HK(m)的数组下标。
题解:打表发现HK数组是123456789 123456789 123456789.............
   得出递归公式 ans=(n-1)*9+m;
   注意n高精度取余,用公式取余一下就行了。
   注意n=0的时候即存在第0个HK(m)的最小的数组下标,即ans的最小值也就是x最小值1。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
char c[];
int main()
{
ll i,n,m,cas=;
while(scanf("%s",c)!=EOF)
{
getchar();
scanf("%lld",&m);
int len=strlen(c);
n=c[]-'';
if(n==)
{
printf("Case #%lld: 1\n",cas++);
continue;
}
for(i=;i<len;i++)
n=(n*+c[i]-'')%mod;
ll ans=(*n-+m+mod)%mod;
printf("Case #%lld: %lld\n",cas++,ans); //注意cas是long long 要用%lld
}
return ;
}

NEFU 2016省赛演练一 B题(递推)的更多相关文章

  1. NEFU 2016省赛演练一 I题 (模拟题)

    这题没名字 Problem:I Time Limit:2000ms Memory Limit:65535K Description Now give you an interger m and a s ...

  2. NEFU 2016省赛演练一 F题 (高精度加法)

    Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...

  3. UVa 11040 Add bricks in the wall (水题递推)

    题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - ...

  4. [luogu4310] 绝世好题 (递推)

    传送门 题目描述 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). 输入输出格式 输入格式: 输入文件共2行. 第一行包括 ...

  5. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  6. (翻译)2016美国数学建模MCM E题(环境)翻译:我们朝向一个干旱的星球?

    PROBLEM E: Are we heading towards a thirsty planet? Will the world run out of clean water? According ...

  7. 经典算法题每日演练——第十七题 Dijkstra算法

    原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...

  8. 经典算法题每日演练——第十一题 Bitmap算法

    原文:经典算法题每日演练--第十一题 Bitmap算法 在所有具有性能优化的数据结构中,我想大家使用最多的就是hash表,是的,在具有定位查找上具有O(1)的常量时间,多么的简洁优美, 但是在特定的场 ...

  9. 经典算法题每日演练——第八题 AC自动机

    原文:经典算法题每日演练--第八题 AC自动机 上一篇我们说了单模式匹配算法KMP,现在我们有需求了,我要检查一篇文章中是否有某些敏感词,这其实就是多模式匹配的问题. 当然你也可以用KMP算法求出,那 ...

随机推荐

  1. centos命令

     alt + z 打开终端(自定义命令)  su 切换到root

  2. WPF 窗口自定义拉伸

    .NET技术交流群 199281001 .欢迎加入. //自定义窗体拉伸 public HwndSource _HwndkaifaSource; private const int WM_SYSCOM ...

  3. 闲来无事,用Java的软引用写了一个山寨的缓存

    闲来无事,用Java的软引用写了一个山寨的缓存 博客分类: java基础 众所周知java中的引用分为 StrongReference.SoftReference.WeakReference.Phan ...

  4. 基础知识系列☞GET和POST→及相关知识

    参考资料: [1].<IT企业必读的200个.Net面试题> [2].http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.htm ...

  5. java笔记--查看和修改线程的优先级

    查看和修改线程的优先级 java中每一个线程都有优先级属性,在默认情况下,新建的线程的优先级与创建该线程的线程优先级相同.每当线程调度器选择要运行的线程时,通常选择优先级较高的线程. 注:线程的优先级 ...

  6. js打印(控件)及多种方式

    非常好用的LODOP打印控件 Lodop打印控件简单使用方法 1.安装. 2.调用LodopFuncs.js文件. 3.增加OBJECT对象 <script language="jav ...

  7. error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不匹配值“2”

    error: vtkCommon.lib(vtkSmartPointerBase.obj) : error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项:值“0”不 ...

  8. 跟着百度学PHP[1]-if条件嵌套

    权当自己的学习笔记.望大牛们切勿参考.如若发现错误,万望指出!  慕课任务 假设在发工资的时候,不仅判定性别,还要判定男性是否有房,没有房,可以发放住房补贴,对于女性,判定是否怀孕,怀孕还有怀孕补贴. ...

  9. C# 浅谈接口的优势

    总结了一下接口的小优势,可以便于新手理解为什么要用接口,用接口有什么好处. 1.接口的定义: 关键字:interface,接口名一般大写I开头,接口中定义方法,但是不实现方法 interface IB ...

  10. 最近win7更新后出现第二次打开IDE(delphi2007)的时候提示无法打开"EditorLineEnds.ttr"这个文件

    kb2982791 - 2014年8月12日更新 - http://support.microsoft.com/kb/2982791kb2970228 - 2014年8月12日更新 - http:// ...