NEFU 2016省赛演练一 B题(递推)
来源:互联网 发布:点餐宝电脑软件价格 编辑:程序博客网 时间:2024/06/08 10:42
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 EOFEach 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 12 22 1
Sample Output
Case #1: 1Case #2: 11Case #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 numberIn 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 1000000007using namespace std;typedef long long ll;char c[100005];int main(){ ll i,n,m,cas=1; while(scanf("%s",c)!=EOF) { getchar(); scanf("%lld",&m); int len=strlen(c); n=c[0]-'0'; if(n==0) { printf("Case #%lld: 1\n",cas++); continue; } for(i=1;i<len;i++) n=(n*10+c[i]-'0')%mod; ll ans=(9*n-9+m+mod)%mod; printf("Case #%lld: %lld\n",cas++,ans); //注意cas是long long 要用%lld } return 0;}
0 0
- NEFU 2016省赛演练一 B题(递推)
- NEFU 2016省赛演练一 I题 (模拟题)
- NEFU 2016省赛演练一 F题 (高精度加法)
- B. Working out (递推dp )
- ACM(递归递推—B)
- Codeforces 892 B. Wrath (递推)
- 递归递推 B
- NEFU OJ 205 最小树(一)
- NEFU 748 A+B+C大数版 大数模板题
- Codeforce 414B(递推)
- codeforces 289B 递推
- Codeforce 429B(递推)
- 递推递归练习 B
- 递推递归练习B
- 递推递归练习B
- 《递归递推练习》B
- 递归递推练习 B
- 递归递推B-王二小切饼
- lamp部署 find mysql命令行 time() input date iptables 2016.06.12回顾
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
- Light OJ 1199 - Partitioning Game (博弈sg函数)
- PHP 使用curl库来发送GET,POST请求,处理json格式数据
- 处理浏览器兼容所遇到的问题总结
- NEFU 2016省赛演练一 B题(递推)
- NEFU 2016省赛演练一 F题 (高精度加法)
- svn服务器的配置和使用
- ProgressBar在Dialog中会虚的问题。
- NEFU 2016省赛演练一 I题 (模拟题)
- Light OJ 1393 Crazy Calendar (尼姆博弈)
- NEFU 1146 又见A+B
- NEFU 1151 特殊的质数
- CSDN markdown快捷键, 自备用