Educational Codeforces Round 70 (Rated for Div. 2) D - Print a 1337-string...

题意:给你一个n,你弄出n个一个子序列为1337的s字符串

思路:s限制的长度为10^5,所以找出33小于等于n的最大组合数C(k,2),弄出k-2个3,剩下的再补齐剩余n-C[k,2]跟2个33搭配就行;

 1 #include<iostream>
 2 #include<algorithm>
 3 #define ll long long 
 4 using namespace std;
 5 const int N = 1000010;
 6 ll c[N];
 7 ll C(ll n, ll m)
 8 {
 9     ll ans = 1;
10     for (int i = 1; i <= m; i++)
11     {
12         ans = ans * (n - m + i) / i;
13     }
14     return ans;
15 }
16 void init()
17 {
18     for (int i = 1; i <= N - 5; i++)
19         c[i] = C(i, 2);//求出3数字的组合数
20 }
21 int main()
22 {
23     init();
24     ll t;
25     cin >> t;
26     while (t--)
27     {
28         ll n;
29         cin >> n;
30         ll x = 2, y;
31         for (int i = 2; c[i] <= n; i++)
32         {
33             x = i;//3
34         }
35         y = n -c[x];//1的个数
36         cout << "1";
37         for (int i = 1; i <= x - 2; i++)
38             cout << 3;
39         for (int i = 1; i <=y; i++)
40             cout << 1;
41         
42         cout << "337" << endl;
43     }
44 }

猜你喜欢

转载自www.cnblogs.com/lv-jie/p/12916937.html