码迷,mamicode.com
首页 > 其他好文 > 详细

CF1295A Display The Number

时间:2020-01-30 14:36:37      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:ref   names   http   class   void   temp   char   getc   amp   

我的blog

题目链接:CF1295A Display The Number

\[description\]

输入\(n\)

输出最多使用\(n\)个小木棍能摆放的数字最大是多少

小木棍摆放每个数字的方式如下图:
技术图片

\[solution\]

贪心

越多位的数肯定越大

我们看到\(1\)所需的小木棍最少,所以要尽量多的选择\(1\),注意当\(n\)为奇数时,第一位选\(7\)明显比选\(1\)更优

\[code\]

#include<cstdio>
using namespace std;
template<typename T>
inline void read(T&x)
{
    x=0;
    char s=(char)getchar();
    bool flag=false;
    while(!(s>='0'&&s<='9'))
    {
        if(s=='-')
            flag=true;
        s=(char)getchar();
    }
    while(s>='0'&&s<='9')
    {
        x=(x<<1)+(x<<3)+s-'0';
        s=(char)getchar();
    }
    if(flag)
        x=(~x)+1;
    return;
}
int num,n,T;
int main()
{
    read(T);
    while(T--)
    {
        read(n);
        num=n>>1;
        if(n&1)
        {
            putchar('7');
            --num;
        }
        while(num--)
            putchar('1');
        putchar('\n');
    }
    return 0;
}

CF1295A Display The Number

标签:ref   names   http   class   void   temp   char   getc   amp   

原文地址:https://www.cnblogs.com/wangjunrui/p/12242542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!