数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

 

题目传送门

 1 /*
 2     数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了
 3         另外不足一个区间的直接计算个数就可以了 
 4 */
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <iostream>
 8 #include <algorithm>
 9 #include <cstring>
10 using namespace std;
11 
12 typedef unsigned long long ull;
13 int get_len(ull x)
14 {
15     int ret = 0;
16     while (x) {
17         x /= 10;    ret++;
18     } 
19     return ret;
20 }
21 
22 
23 int main(void)      //Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
24 {
25     //freopen ("B.in", "r", stdin);
26 
27     ull w, m, k;
28     while (cin >> w >> m >> k) {
29         int len = get_len (m);   ull mx = 0;
30         for (int i=1; i<=len; ++i) {
31             mx = mx * 10 + 9;
32         }
33 
34         ull ans = 0; ull cost = (mx - m + 1) * k * len;
35         while (cost <= w) { 
36             w -= cost;  ans += (mx - m + 1);
37             len++;  m = mx + 1; mx = mx * 10 + 9;
38             cost = (mx - m + 1) * k * len;
39         }
40         
41         ans += w / (len * k);
42         cout << ans << endl;
43     }
44 
45     return 0;
46 }
 1 #include <cstdio>
 2 #include <cmath>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <cstring>
 6 using namespace std;
 7 
 8 typedef long long ll;
 9 int get_len(ll x)
10 {
11     int ret = 0;
12     while (x) {
13         x /= 10;    ret++;
14     } 
15     return ret;
16 }
17 
18 
19 int main(void)      //Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
20 {
21     //freopen ("B.in", "r", stdin);
22 
23     ll w, m, k;
24     while (scanf ("%I64d%I64d%I64d", &w, &m, &k) == 3) {
25         int len = get_len (m);   ll mx = 0;
26         for (int i=1; i<=len; ++i) {
27             mx = mx * 10 + 9;
28         }
29 
30         ll ans = 0, now = 0, tot = 0;
31         while (true) {
32             now = mx - m + 1;   tot = w / (k * len);
33             if (now < tot) {
34                 ans += now; w -= now * k * len;
35                 m = mx + 1; mx = mx * 10 + 9;   len++;
36             }
37             else {
38                 ans += tot; break;
39             }
40         }
41         
42         printf ("%I64d\n", ans);
43     }
44 
45     return 0;
46 }
按个数比较

 

转载于:https://www.cnblogs.com/Running-Time/p/4658514.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值