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

  • 相关阅读:
    [django]django models最佳实战
    [vue]模拟移动端三级路由: router-link位置体现router的灵活性
    [js]顶部导航和内容区布局
    [django]django查询最佳实战
    [vue]webpack使用样式
    [vue]webpack中使用组件
    [vue]组件的导入
    [django]django权限简单实验
    [django]前后端分离之JWT用户认证
    [django]drf知识点梳理-权限
  • 原文地址:https://www.cnblogs.com/hsd-/p/5164355.html
Copyright © 2011-2022 走看看