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语言拾遗(一):整型提升
    高性能分布式计算与存储系统设计概要——暨2012年工作3年半总结(下) <转>
    c10k测试:每连接新线程回显服务器(echo server) (转)
    高性能分布式计算与存储系统设计概要——暨2012年工作3年半总结(上) <转>
    java基础总结equals与==
    Java的运行机制概括
    Java 基础总结反射的基本操作
    python爬取基础网页图片
    px,dp,sp以及像素密度
  • 原文地址:https://www.cnblogs.com/hsd-/p/5164355.html
Copyright © 2011-2022 走看看