1 second
256 megabytes
standard input
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.
The only line contains two integers a, b (1 ≤ a ≤ b ≤ 10) — the first and the last number typed by Max.
Print the only integer a — the total number of printed segments.
1 3
12
10 15
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\n",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\n",ans);
return 0;
}
orzzz