zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 6 B. Grandfather Dovlet’s calculator 暴力

    B. Grandfather Dovlet’s calculator
     

    Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).

    Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.

    For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.

    Input

    The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.

    Output

    Print the only integer a — the total number of printed segments.

    input
    1 3
    output
    12
     
    题意:
      给你0~9分别需要几根火柴拼成,现在 给定a,b,让你计算从a到b这个范围内 每一数位用到的火柴总和
    题解:
      可以打表出10^6内每个数需要的火柴
      在计算~~~~~~~
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1000001;
    ll H[N][11],a,b;
    int M[20] = {6,2,5,5,4,5,6,3,7,6};
    int main() {
        for(int i = 1; i <= 1000000; i++) {
            int tmp = i;
            while(tmp) H[i][tmp%10]++,tmp/=10;
        }
        ll ans = 0 ;
        scanf("%I64d%I64d",&a,&b);
        for(int i = a; i <= b; i++) {
            for(int j = 0; j <= 9 ; j ++) ans+= M[j] * H[i][j];
        }
        printf("%I64d
    ",ans);
        return 0;
    }
  • 相关阅读:
    搞懂树状数组
    C#接口(Interface)
    C#接口(Interface)
    C#运算符的重载
    C#和C++的区别(一)
    hdu1874 畅通工程续
    hdu1874 畅通工程续
    C#多态性
    C#多态性
    C#继承
  • 原文地址:https://www.cnblogs.com/zxhl/p/5155690.html
Copyright © 2011-2022 走看看