Educational Codeforces Round 81 (Rated for Div. 2) A 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 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.

Input

The 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.

Output

For 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.

菜狗我的思路

写了一大堆没用的东西

int a[10] = {0};
const int CNM = 998244353;
void init()
{

    a[5] = 9;
    a[3] = 7;
    a[2] = 1;
}
int main()
{
    int t;
    cin >> t;
    init();
    while (t--)
    {
        int n;
        cin >> n;
        if (n<=CNM*2)
        {
            if (n<4)
                printf("%d",a[n]);
            else{
                if (n%2 == 0)
                    for (int i = 1; i <= n/2; i++)
                        printf("1");
                else
                {
                    printf("7");
                    for (int i = 2; i <= n/2; i++)
                        printf("1");
                }
            }
            printf("\n");
        }
        else{
            int y = n - CNM*2;
            for (int i = 1; i<=CNM ; i++)
            {
                bool f= false;
                for (int j = 5; j>= 3; j--)
                {
                    if (a[j] == 0) continue;
                    //printf("y = %d\n", y);
                    if (y-j + 2>=0)
                    {
                        y-=(j-2);
                        printf("%d", a[j]);
                        f = true;
                        break;
                    }
                }
                if (f) continue;
                printf("1");
            }
            printf("\n");
        }
    }
}

大佬思路:其实就是先摆1,因为位数多的肯定大然后多出来的灯就让原来的最前面的那个1变为7就可以了。

#include<iostream>
#include<string>
#include <cstdlib>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<algorithm>
// #pragma comment(linker, "/STACK:1024000000,1024000000")
// #define pi acos(-1)
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
#define CNM ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)

inline int read() {
    int s = 0, w = 1;
    char ch = getchar();
    while (ch<‘0‘ || ch>‘9‘) { if (ch == ‘-‘)w = -1; ch = getchar(); }
    while (ch >= ‘0‘ && ch <= ‘9‘) s = s * 10 + ch - ‘0‘, ch = getchar();
    return s * w;
}
#define local
#ifdef local
#endif

#define MAX 10233
#define LCH(i) ((i) << 1)
#define RCH(i) ((i) << 1 | 1)

int main()
{
    CNM;
    int t; cin >> t;
    while (t--)
    {
        int n; cin >> n;
        int cnt = n / 2;
        string s = "";
        for (int i = 0; i < cnt; i++)
        {
            s += "1";
        }

        if (n & 1)
        {
            s = "7" + s;
            s.pop_back();
        }
        cout << s << endl;
    }
}

原文地址:https://www.cnblogs.com/hulian425/p/12242644.html

时间: 2024-11-07 08:01:52

Educational Codeforces Round 81 (Rated for Div. 2) A Display The Number的相关文章

Educational Codeforces Round 81 (Rated for Div. 2) C. Obtain The String

题目链接:http://codeforces.com/contest/1295/problem/C 题目:给定字符串s,t.  给定一个空串z,需要按照规则把z构造成 string z == string t 的字符串. 规则:有限次从s中任取子序列p,然后进行 string z += string p的操作, s不变. 问能不能构造出p,不能输出-1,可以得话最少几次可以构造出. 大致的想法就是n倍的s字符串串联,然后剔除不必要的字符,就可以得出z, 求最少的倍数n是多少. 主要思路就是用二分

Educational Codeforces Round 81 (Rated for Div. 2) B. Infinite Prefixes

题目链接:http://codeforces.com/contest/1295/problem/B 题目:给定由0,1组成的字符串s,长度为n,定义t = sssssss.....一个无限长的字符串. 题目定义一个平衡值x,取t的任意前缀Q,如果Q满足cnt(0,q) - cnt(1,q) = x,即Q中0 的个数-1的个数= x,说明当前的Q是满足题意得一个前缀,问满足x的前缀有多少个, 如果x = ∞,则输出-1. input 6 10 010010 题目给定说q的长度为28,30,32是平

【Educational Codeforces Round 81 (Rated for Div. 2) A】Display The Number

题目链接 [题解] 优先用2个棒子来凑1. 如果为奇数的话,多出来一根用3根来凑个7放在开头 [代码] #include <bits/stdc++.h> using namespace std; int main(){ #ifdef LOCAL_DEFINE freopen("E:\\rush.txt","r",stdin); #endif // LOCAL_DEFINE ios::sync_with_stdio(0),cin.tie(0); int T

Educational Codeforces Round 81 (Rated for Div. 2)

A - Display The Number 题意:给n根火柴,拼出最大的数字. 题解:肯定是数字越多越大,所以尽可能多拿最便宜的2根火柴一个"1",多余的肯定是拿一个"7",由于n>=2,没有特例. void test_case() { int n; scanf("%d", &n); if(n % 2 == 1) { printf("%d", 7); n -= 3; } while(n) { printf(&q

【Educational Codeforces Round 81 (Rated for Div. 2) C】Obtain The String

题目链接 [题解] 显然我们得按顺序获得目标t的每个字符. 对于t[0],t[1],t[2],t[3]... 我们可以在s中找到这么一个子序列. 显然如果找到尾巴还是没有需要的t[i]. 就得从s[0]开始重新开始顺序找. (然后答案递增,因为表示要重新开始加一个子序列了) 但是如果这么直接找的话,复杂度是O(|s||t|)的 是无法接受的. 所以我们可以另外开一个数组 next[i][j] 表示在i-1位置,如果要找下一个紧接着的j的话,需要到哪个位置找.(这个next数组整体往左偏移了下,便

【Educational Codeforces Round 81 (Rated for Div. 2) B】Infinite Prefixes

题目链接 [题解] 把0看成是1,把1看成是-1 求一个前缀和. pre[i] = pre[i-1]+1 得到delta = pre[n] 显然对于每个位置的值pre[i] 再复制一遍s的话. 下一个s的该位置,也即i+n的前缀和显然为pre[i]+delata 那么无限的情况就很显然了. 即pre[i]==x,而且delata==0. 只要出现一个这种情况,就是无限. 其他情况,每个位置都会朝着目标远离或者毕竟. 看看差值不是不是delta的整数倍就可以了. 如果是的话,说明可以变成x [代码

Educational Codeforces Round 81 (Rated for Div. 2)F(线段树)

预处理把左集划分为大小为1~i-1时,把全部元素都移动到右集的代价,记作sum[i]. 然后枚举终态时左集的大小,更新把元素i 留在/移动到 左集的代价. 树状数组/线段树处理区间修改/区间查询 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 #define ll long long 5 const int N=2e5+7; 6 struct Tree{ 7 ll minn,la

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is