B - 家
来源:互联网 发布:好看编程图片 编辑:程序博客网 时间:2024/04/28 05:57
Description
We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3, S(114514) = 6.
You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(n)·k to add the number nto the sequence.
You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.
Input
The first line contains three integers w (1 ≤ w ≤ 1016), m (1 ≤ m ≤ 1016), k (1 ≤ k ≤ 109).
Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
The first line should contain a single integer — the answer to the problem.
Sample Input
9 1 1
9
77 7 7
7
114 5 14
6
1 1 2
0
代码:
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>using namespace std;char bb[100];__int64 ss(__int64 tmp){ __int64 i,times=0;for (;;){ tmp=tmp/10; if (tmp) { times++; } else { break; }}times++;return times;}int main(){__int64 w,m,k;scanf("%I64d%I64d%I64d",&w,&m,&k); w=w/k; //防止溢出,不用也行此题__int64 len=0,cost=0;__int64 i;for (i=m;;i++){ __int64 tmpp=ss(i); //、、、、、、、、、、、、、、、、、、、、、、、此处为关键一,缝十进位,减少计算量,一开始也想到了 if (cost+( pow((double)10,(int)tmpp)-i)*(tmpp)<=w){cost+=( pow((double)10,(int)tmpp)-i)*(tmpp) ;len+= pow((double)10,(int)tmpp)-i;i+=( pow((double)10,(int)tmpp)-i)-1;continue;}//、、、、、、、、、、、、、、、、、、、、、、、
len+=(w-cost)/tmpp; ////此处为关键二 ,当最后一位不能进十的时候,误以为一个一个加上去就好了。然后当w足够大k足够小的时候,这个计算量非常大,因此 需要
break; }printf("%I64d\n",len);return 0;}
- B - 家
- b
- b
- b
- //b
- B
- b
- B
- B
- B
- B
- b
- B
- B
- B
- B
- B
- B
- 指针取值(*)与自增(++)运算
- 毕晓英3-28第二章6-9题
- 类的加载顺序
- spring定时调用数据库存储过程
- Ubuntu开启远程控制的方法
- B - 家
- URAL 1507 Difficult Decision 矩阵快速幂
- 动态页面技术(jsp)基础知识
- jsp课堂笔记1
- 异步任务AsyncTask
- 交换算法
- http://honx.in/i/VN7g_ez5NHNkllfB红杏邀请码,还是挺好用的
- 线性表-链式实现-单链表
- 使用FrameLayout+ScrollView+RelativeLayout嵌套布局,实现仿Windows Phone