码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-19 14:55:30      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

 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 }
按个数比较

 

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

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4658514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!