Educational Codeforces Round 6 (B)模拟
2016-01-22 01:40
405 查看
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
output
input
output
题意:给你区间[L,R],问从L打印到R,至少需要多少线段。
题解:先数一下每个数字需要多少笔画,然后直接模拟可以了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
int ans[100]={6,2,5,5,4,5,6,3,7,6};
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int n,m,x,y;
while(~scanf("%d%d",&n,&m))
{
int sum=0;
for(int i=n;i<=m;i++)
{
if(i<10)
sum+=ans[i];
else
{
int tmp=i;
while(tmp>0)
{
sum+=ans[tmp%10];
tmp/=10;
}
}
}
printf("%d\n",sum);
}
return 0;
}
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
题意:给你区间[L,R],问从L打印到R,至少需要多少线段。
题解:先数一下每个数字需要多少笔画,然后直接模拟可以了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
int ans[100]={6,2,5,5,4,5,6,3,7,6};
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int n,m,x,y;
while(~scanf("%d%d",&n,&m))
{
int sum=0;
for(int i=n;i<=m;i++)
{
if(i<10)
sum+=ans[i];
else
{
int tmp=i;
while(tmp>0)
{
sum+=ans[tmp%10];
tmp/=10;
}
}
}
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- Educational Codeforces Round 6 (A)贪心
- tensorflow源代码方式安装
- 关于Nginx+Gunicorn+uwsgi+后端框架到app架构梳理和思考
- js中变量声明的问题
- Educational Codeforces Round 6 620C Pearls in a Row(stl)
- 【20160122】深夜难眠,觉晓此生
- C语言判断一个字符串是否是另一个字符串的子串
- Android TextView控件 之滚动文字效果
- UI笔记之UIButton
- C 二分查找算法
- LUA相关基础知识
- MFC获取光标相对于控件所在行
- On Mac platform,Using Eclipse + PyDev Plugins + Python to build a Python development environment
- web.xml配置以及servlet生命周期
- [工作中的设计模式]单例模式singleton
- CCF模板生成系统
- LeetCode 51. N-Queens
- linux常用命令总结
- 百度云的自动备份的思考
- [R] foreach package