Educational Codeforces Round 81 (Rated for Div. 2) A Display The Number
You have a large electronic screen which can display up to 10 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 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 segments.
Your program should be able to process t different test cases.
The first line contains one integer 1≤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 2≤n≤105) — the maximum number of segments that can be turned on in the corresponding testcase.
It is guaranteed that the sum of 105.
For each test case, print the greatest integer that can be displayed by turning on no more than 64-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(" "); } 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 ", y); if (y-j + 2>=0) { y-=(j-2); printf("%d", a[j]); f = true; break; } } if (f) continue; printf("1"); } printf(" "); } } }
大佬思路:其实就是先摆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 "; // 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; } }