Cattle passenger Anhui University freshman season G

            Portal :: https://ac.nowcoder.com/acm/contest/2720/G

A configuration that Italy :: string (string of length <= 1e9) if and only contains the n "AHUICPC" sequence and length of the string <= 1e5

  Ideas ::

When you add in front of each string ( "UICPC") 1 th "AH", constitutes a total of (i +1) * i / 2 subsequences, the optimal solution can be constructed so that the shortest possible sequence;

Of course, why is configured to the optimal length of 2, and is configured the same way as the time length of 3, although can be constructed so many sub-sequence, but will be fried;

For example "AHAHAHAH UICPC" You will find the sum of 4 + 3 + 2 + 1 = 10 (arithmetic sum) the sequence

Therefore, we must first find the maximum i satisfying (i + 1) * i / 2 <n, and k for the extra part we can not find a location (i.e., the configuration of the k-th "AH" position before adding on a "a") which is the initial position meet with just constructed k subsequences, apparently it took only a unit length

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n;
 8     scanf("%d",&n);
 9     if(n==1){
10         printf("AHUICPC");return 0;
11     }
12     int k;
13     for(int i=1;;i++){
14         if((ll)(i+1)*i/2<(ll)n){
15             k=i;
16         }
17         else{
18             break;
19         }
20     }
21     int t=(n-(k+1)*k/2);
22     for(int i=1;i<=t;i++){
23         if(i==t-k+1){
24             printf("AAH");
25         }
26         else{
27             printf("AH");
28         }
29     }
30     printf("UICPC");
31     return 0;
32 }

 Please indicate deficiencies! ! !

Guess you like

Origin www.cnblogs.com/sj-gank/p/11972620.html