• 数学 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
    ", ans);
    43     }
    44 
    45     return 0;
    46 }
    按个数比较
    编译人生,运行世界!
  • 相关阅读:
    CSS – rem, em, px
    CSS – Variables
    go等待子协程完成再结束
    go原生mysql链接
    [恢]hdu 2511
    linux中竖线'|',双竖线‘||’,&和&&的意思
    SSH隧道:端口转发功能详解
    shell脚本执行返回的状态码
    第1章 ssh命令和SSH服务详解
    shell脚本中各种括号的区别以及用法
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4658514.html
Copyright © 2020-2023  润新知