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. bzoj3555 企鹅QQ

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1640  Solved: 613 Description P ...

  2. springmvc常用注解标签详解

    1.@Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...

  3. --hdu 1114 Piggy-Bank(完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 AC code: #include<bits/stdc++.h> using nam ...

  4. Graphtree--zabbix增强功能(一屏展示所有内容)

    Graphtree--zabbix增强功能 Graphtree由OneOaaS开发并开源出来. 功能 集中展示所有分组设备 集中展示一个分组图像 集中展示一个设备图像 展示设备下的Applicatio ...

  5. C语言strchr()函数:查找某字符在字符串中首次出现的位置

    头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为:    char * strchr (const char *str, ...

  6. centOS 下 VSFTP的安装和设置

    http://blog.csdn.net/swiftshow/article/details/7367609 一.FTP的安装 1.检测是否安装了FTP :[root@localhost ~]# rp ...

  7. Dual Palindromes

    Dual PalindromesMario Cruz (Colombia) & Hugo Rickeboer (Argentina) A number that reads the same ...

  8. java类加载器

    1.什么是类加载器?类加载器实现什么功能? 类加载器(Class Loader)是用来加载java类到java虚拟机(JVM)中,加载步骤: java编译器编译java源文件(*.java文件)成字节 ...

  9. ASP.NET中树型DropDownList的绑定

    首先设计好数据库,假设数据库有三个字段Id,ParentId,Name.ParentId是树性结构必须的,就是节点的父节点id,假设跟节点id都是0.下面就可以绑定了! 思路应该很简单,就是先绑定根节 ...

  10. 成为Android高手必须掌握的28大项内容和10个建议

    (一)成为Android高手必须掌握的8项基本要求 [1] Android操作系统概述1. Android系统架构.           2. Android利用设计理念.           3. ...