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