hihoCoder #1432 : JiLi Number(吉利数)

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

Description - 题目描述

Driver Ji likes the digit "1". He has an accumulator which shows the sum of input number. He lists all of positive number no more than N and starts counting from one, two, three...Every time he counts a number he will add the number of digit "1" in this number to accumulator at the same time. The amazing thing happens! At some times, when he finishes counting a number X, the number which on the accumulator is X exactly, he will regard X as "JiLi Number" which means lucky number. Now he wants to know the number of "JiLi Numbers" and the biggest "JiLi Number" no more than N.

Ji司机喜欢数字””。他有一个累加器可以显示输入数的和。他列出了所有不超过N的正整数,并且开始1,,...地数了起来。每当他数到一个数时,会顺手把其数字””的个数放入累加器。不可思议的事发生了!有时他数完一个数X,累加器中的数也恰好为X,他将X称作”吉利数”,表示十分幸运的数字。现在他想知道在不超过N的情况下”吉利数”的数量与最大”吉利数”。

CN

Input - 输入

There are several test cases and the each test case is a line contains an positive integer N.(1<N≤10100)

多组数据,每组数据仅有一行,每行一个正整数N。(<N≤^)

CN

Output - 输出

For each test case, output two integers which donates the number of "JiLi Numbers" and the biggest "JiLi Number".

对于每个测试用例,输出两个整数分别表示”吉利数”的数量与最大的”吉利数”。

CN

Sample Input - 样例输入

1
100000000000

Sample Output - 样例输出

1 1
83 1111111110

题解

  暴力枚举,样例刚刚好给出了最大与最小的情况……
  至于证明,证不出来,似乎因为是十进制数所以不能超过十位数,到了后面累加器中的值的增长速度明显超过了数数速度,应该是没有交集了……

代码 C++

 #include<cstdio>
#include <algorithm>
#define ll long long
#define mx 84
ll opt[mx] = {
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
0x7FFFFFFFFFFFFFFF
};
int main(){
char rd[];
int i;
ll tmp;
while (gets(rd)){
tmp = ;
for (i = ; i < && rd[i]; ++i) tmp = tmp * + rd[i] - '';
i = std::upper_bound(opt, opt + mx, tmp) - opt;
printf("%d %lld\n", i, opt[i - ]);
}
return ;
}

hihoCoder 1432 : JiLi Number(吉利数)的更多相关文章

  1. [LeetCode] Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  2. [LeetCode] Strobogrammatic Number 对称数

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  3. [LeetCode] Happy Number 快乐数

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  4. Ugly number丑数2,超级丑数

    [抄题]: [思维问题]: [一句话思路]:Long.valueOf(2)转换为long型再做 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 ...

  5. hdu 3709 Balanced Number(平衡数)--数位dp

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  6. [LeetCode] 263. Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  7. [LeetCode] 136. Single Number 单独数

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  8. [LeetCode] 202. Happy Number 快乐数

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  9. [LeetCode] 246. Strobogrammatic Number 对称数

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

随机推荐

  1. git用.gitignore忽略指定文件

    .gitignore 配置文件用于配置不需要加入版本管理的文件,配置好该文件可以为我们的版本管理带来很大的便利,以下是个人对于配置 .gitignore 的一些心得. 1.配置语法: 以斜杠“/”开头 ...

  2. PhpStorm 4.0 & 5.0 部署本地Web应用 (转)

    1.创建新的项目(project),创建完成之后单击工具栏的应用运行/调试(Select Run/Debug Configuration)的下拉菜单弹出 Edit Cofigurations选项,单击 ...

  3. idea转eclipse 设置注意。

    下载适合的eclipse

  4. [转]asp三级select菜单联动(加数据库)

    '数据库结构'类别1表名称:a 字段:ID,Name 说明:ID为主键是类别1的ID值,Name为类别1的名称'类别2表名称:aa 字段:ID,aID,Name 说明:ID为主键是类别2的ID值,aI ...

  5. 【001:go语言的一些语法基础】

    1. 循环语句 Go只有for一个循环语句关键字,但支持3种形式 初始化和步进表达式可以是多个值 条件语句每次循环都会被重新检查,因此不建议在条件语句中 使用函数,尽量提前计算好条件并以变量或常量代替 ...

  6. Oracle中的日期加减

    加法   select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate,add_months(sysdate ...

  7. Mvc4中使用Spring.Net实现IOC和DI

    一个Hello类,一个IHello接口 1.引用dll 2.修改Global文件 (SpringMvcApplication) 3.控制器添加属性 4.WebConfig配置 5.Spring.xml ...

  8. javascript的escape()方法

    escape() 方法:采用ISO Latin字符集对指定的字符串进行编码.所有的空格符.标点符号.特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码 ...

  9. 关于IE11版本下JS中时间判断的问题

    最近在做代码的优化及浏览器的兼容问题.遇到了谷歌.火狐.360兼容模式.IE(8以上)版本对时间判断大小的问题 . 在谷歌.火狐.360.IE11以下IE8以上版本下 var d1="201 ...

  10. PMP考试

    今天是第二次PMP模拟考试,得了146分,比上次高25分,这次题目相对简单些,看来昨晚的复习没有白费,还是有效果的. 有些题目影响还是比较深刻,老外的项目管理思想是先规划好一切再执行(管理),比如信息 ...