codeforcesDIV2-A

不知道为什么,回家之后codeforces就进不去,然后也报不了名,刚才本来准备上床玩手机了,突然看到有人在牛客交流群里发了题面,就读了一下题,A题还是挺简单的。

在这里插入图片描述


A. Display The Number
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a large electronic screen which can display up to 998244353998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 77 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 1010 decimal digits:

As you can see, different digits may require different number of segments to be turned on. For example, if you want to display 11, you have to turn on 22 segments of the screen, and if you want to display 88, all 77 segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than nn segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than nn segments.Your program should be able to process tt different test cases.
InputThe first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases in the input.Then the test cases follow, each of them is represented by a separate line containing one integer nn (2≤n≤1052≤n≤105) — the maximum number of segments that can be turned on in the corresponding testcase.It is guaranteed that the sum of nn over all test cases in the input does not exceed 105105.
OutputFor each test case, print the greatest integer that can be displayed by turning on no more than nn segments of the screen. Note that the answer may not fit in the standard 3232-bit or 6464-bit integral data type.

input
2
3
4
output
7
11

由于学校周赛遇到过很多次类似的题面背景(火柴棒拼数字),所以这个题我很快就读懂了。


我们来看一下下图,显然数字0需要六画、数字1需要两画,以此类推。

在这里插入图片描述

然后题目问,给你一个n,用n画能组成的最大整数是多少。

其实很简单,首先一个数要尽可能的大,首先需要考虑的是位数,其次是首位,因此我们要尽量选笔画少的数字,显然是1,只需要两画,那么当n为偶数时,n/2个1肯定是最大的数。然后我们再来考虑奇数,毋庸置疑的是,除了第一位外,后面肯定全是1,再观察一下所有数字的所需要的笔画,显然只需三画的较大整数7是最优的。

综上所述,代码很简单:

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <map>
#include <math.h>
#include <set>
#include <vector>
#include <stack>
#include <sstream>
#define ll long long
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        if (n % 2 == 0)
        {
            n /= 2;
            while (n--)
                cout << "1";
            cout << endl;
        }
        else
        {
            cout << "7";
            n -= 3;
            n /= 2;
            while (n--)
                cout << "1";
            cout << endl;
        }
    }
    return 0;
}
发布了55 篇原创文章 · 获赞 54 · 访问量 7399
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章