NEFU 2016省赛演练一 B题(递推)
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题(递推)的更多相关文章
- NEFU 2016省赛演练一 I题 (模拟题)
这题没名字 Problem:I Time Limit:2000ms Memory Limit:65535K Description Now give you an interger m and a s ...
- NEFU 2016省赛演练一 F题 (高精度加法)
Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...
- UVa 11040 Add bricks in the wall (水题递推)
题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - ...
- [luogu4310] 绝世好题 (递推)
传送门 题目描述 给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2<=i<=len). 输入输出格式 输入格式: 输入文件共2行. 第一行包括 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- (翻译)2016美国数学建模MCM E题(环境)翻译:我们朝向一个干旱的星球?
PROBLEM E: Are we heading towards a thirsty planet? Will the world run out of clean water? According ...
- 经典算法题每日演练——第十七题 Dijkstra算法
原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...
- 经典算法题每日演练——第十一题 Bitmap算法
原文:经典算法题每日演练--第十一题 Bitmap算法 在所有具有性能优化的数据结构中,我想大家使用最多的就是hash表,是的,在具有定位查找上具有O(1)的常量时间,多么的简洁优美, 但是在特定的场 ...
- 经典算法题每日演练——第八题 AC自动机
原文:经典算法题每日演练--第八题 AC自动机 上一篇我们说了单模式匹配算法KMP,现在我们有需求了,我要检查一篇文章中是否有某些敏感词,这其实就是多模式匹配的问题. 当然你也可以用KMP算法求出,那 ...
随机推荐
- 人工免疫算法-python实现
AIAIndividual.py import numpy as np import ObjFunction class AIAIndividual: ''' individual of artifi ...
- BZOJ2463 谁能赢呢?
Description 小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的 ...
- TCP Socket Establish;UDP Send Package Process In Kernel Sourcecode Learning
目录 . 引言 . TCP握手流程 . TCP connect() API原理 . TCP listen() API原理 . UDP交互过程 . UDP send() API原理 . UDP bind ...
- [IOS Block和delegate的对比]
原文:http://blog.sina.com.cn/s/blog_9e8867eb0102uykn.html 这篇文章建议和前一篇一起看, 另外先弄清楚IOS的block是神马东东. 委托和bloc ...
- HDU2196computer(树上最远距离 + DP)
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 初识A*算法
写这篇文章的初衷是应一个网友的要求,当然我也发现现在有关人工智能的中文站点实在太少,我在这里抛砖引玉,希望大家都来热心的参与. 还是说正题,我先拿A*算法开刀,是因为A*在游戏中有它很典型的用法,是人 ...
- linux(Debian)下安装与MySql的安装、卸载、配置及使用
参考资料:http://www.cnblogs.com/xusir/p/3334217.html 以下是简要记录. 一.安装 安装:apt-get install mysql-server mysql ...
- hdu 1261 字串数
解题思路:ACM紫书 第十章 P319 有重复元素的全排列 答案: 所有数的和的阶乘 除以 每个数阶乘的乘积 因为给定 (26*12)! 会爆掉(long long),这里用java 的BigInte ...
- 锋利的jQuery-1-- :的用法
在一个id为table的表格的tbody中,如果每一行的最后一列的checkbox没有被禁用,则把这行的背景色设置为红色. $( "#table>tbody>tr:has(td: ...
- centos安装gitlab
原文链接: http://www.centoscn.com/image-text/install/2015/0320/4929.html http://www.01happy.com/centos-6 ...