CodeForces 1295 A Display The Number

本文解析了CodeForces平台上的1295A题Display The Number,介绍了如何在电子屏上显示最大可能的整数,当屏幕可以点亮的段落数量有限制时。通过算法确定了在不超过限制的情况下,可以显示的最大数字,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

See this article on my own blog https://dyingdown.github.io/2020/01/30/CodeForces-1295A-Display-The-Number/

A. Display The Number
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output:standard output

You have a large electronic screen which can display up to 998244353 998244353 998244353 decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of 7 7 7 segments which can be turned on and off to compose different digits. The following picture describes how you can display all 10 10 10 decimal digits:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CsCBzA5b-1580321023731)(https://espresso.codeforces.com/39cedf07ce9ef18d7ec074f319640a9857b9f8cb.png)]

As you can see, different digits may require different number of segments to be turned on. For example, if you want to display 1 1 1, you have to turn on 2 2 2 segments of the screen, and if you want to display 8 8 8, all 7 7 7 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 n n n 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 n n n segments.

Your program should be able to process t t t different test cases.

Input

The first line contains one integer t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1t100) — 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 n ( 2 ≤ n ≤ 105 ) n (2≤n≤105) n(2n105) — the maximum number of segments that can be turned on in the corresponding testcase.

It is guaranteed that the sum of n n n over all test cases in the input does not exceed 105 105 105.

Output

For each test case, print the greatest integer that can be displayed by turning on no more than n n n segments of the screen. Note that the answer may not fit in the standard 32 32 32-bit or 64 64 64-bit integral data type.

Example

input
2
3
4
output
7
11

Analysis

The more number it can lighten, the longer digits it can have. So,

1 1 1 uses the less segments.

We make 1 1 1 as many as possible. If there are still segments left that can’t make a complete 1 1 1, we break up one 1 1 1 and let it form 7 7 7 with the rest.(the rest could only be 1 or 0 because 1 1 1 uses two segments)

Code

#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int digits1 = n / 2;
        if(n % 2 == 1) {
            cout << 7;
            for(int i = 1; i < digits1; i ++) {
                cout << 1;
            }
        } else {
            for(int i = 0; i < digits1; i ++) {
                cout << 1;
            }
        }
        cout << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值