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;
    }
  • 相关阅读:
    验证码学习笔记
    字符串String类
    密封关键字sealed
    比较两个对象是否为同一个对象
    Unity让带有Rigidbody组件的游戏对象停止运动
    Unity3d-制作粒子光环特效
    Unity3d实现的十字路口的模拟(三)
    kinect v2
    Unity3D 之射线检测
    FFmpeg X264的preset和tune
  • 原文地址:https://www.cnblogs.com/zxhl/p/5155690.html
Copyright © 2011-2022 走看看