Gym - 101612A 点亮数字

14 篇文章 0 订阅
10 篇文章 0 订阅

Auxiliary Project

Anna has just nished her course project. She has a lot of seven-segment LED displays as leftovers and a small power source. Each display consumes power proportionally to the number of lit segments, e.g. ‘9’consumes twice more power than ‘7’.


这里写图片描述

Anna wonders what is the maximum possible sum of digits she is able to achieve, if her power source is able to light n segments, and she wants to light exactly n segments.

Input

The single line of the input contains one integer n —– the number of segments that should be lit(2<=n<=10^6).

Output

Output a single integer —– the maximum possible sum of digits that can be displayed simultaneously.

Sample Input

4
7
6

Sample Output

4
11
14


如图的数字显示方式,每个线段需要一个能量,有n个能量,在尽可能把所有能量都用上的情况下是的组成的所有的数字之和最大。


通过模拟

noutput
21
37
44
58
614
711
815
921
1018

2个能量是1
3个能量是7
4个能量是4
5个能量是3+2个能量 7+1=8
6个能量是3+3—7+7=14
7个能量是3+4个能量 7+4=11
8个能量是3+3+2个能量 7+7+1=15
发现都是由2、3、4个能量为基础来组成的
so直接对3取模
n%3=0 全是7
n%3=1 把 3+3+3+3+…+3 中最后一个3换成4
n%3=2 最后一个是2点能量3+3+3+…..+2

#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int m = n % 3;
    int c = n / 3;
    if (m == 0)
    {
        return 0 * printf("%d\n", c * 7);
    }
    if (m == 1)
    {
        return 0 * printf("%d\n", (c - 1) * 7 + 4);
    }
    if (m == 2)
    {
        return 0 * printf("%d\n", c * 7 + 1);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值