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\n",ans);
    return 0;
}

 

posted @ 2016-01-24 19:24  meekyan  阅读(301)  评论(0编辑  收藏  举报