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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章