zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 6 B

    B. Grandfather Dovlet’s calculator
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    Sample test(s)
    Input
    1 3
    Output
    12
    Input
    10 15
    Output
    39

    题意: 0-9分别如图所示 每个数字led管由7部分组成 根据不同的数字亮不同的地方
    给一个区间 问这段区间内所有数 得有多少部分亮
    题解: 每位每位的计算

    我的代码998ms
    #include<bits/stdc++.h>
    using namespace std;
    #define LL __int64
    map<int,int>mp;
    map<int,int>mpp;
    int n,m;
    int main()
    {
        mp[0]=6;
        mp[1]=2;
        mp[2]=5;
        mp[3]=5;
        mp[4]=4;
        mp[5]=5;
        mp[6]=6;
        mp[7]=3;
        mp[8]=7;
        mp[9]=6;
        mpp[0]=0;
        int sum=0;
        for(int i=1;i<=1000000;i++)
        {
            int exm=i;
            mpp[i]=sum;
          while(exm!=0)
         {
             mpp[i]+=mp[exm%10];
             sum+=mp[exm%10];
             exm=exm/10;
         }
        }
        scanf("%d%d",&n,&m);
        printf("%d
    ",mpp[m]-mpp[n-1]);
        return 0;
    }
    

      

    我晏的代码62ms

    #include <cstdio>
    #include<bits/stdc++.h>
    #include <cstring>
    #include <ctime>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    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;
    }
    

      

    orzzz

  • 相关阅读:
    C#将List<T>转化为DataTable
    SqlServer常用内置函数
    C#索引器
    验证Textbox的字符长度
    WM消息对应的Message消息中的Lparam和WParam
    对窗体操作的WM消息
    DllImport使用
    C#获取当前路径的七种方法
    注册ActiveX控件
    [转]VS2010中水晶报表安装应用及实例
  • 原文地址:https://www.cnblogs.com/hsd-/p/5164355.html
Copyright © 2011-2022 走看看