HDU4850 Wow! Such String! —— 字符串构造

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4850


代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <vector>
 7 #include <map>
 8 #include <set>
 9 #include <queue>
10 #include <sstream>
11 #include <algorithm>
12 using namespace std;
13 #define pb push_back
14 #define mp make_pair
15 #define ms(a, b)  memset((a), (b), sizeof(a))
16 #define eps 0.0000001
17 typedef long long LL;
18 const int INF = 2e9;
19 const LL LNF = 9e18;
20 const int mod = 1e9+7;
21 const int maxn = 26*26*26*26;
22 int a[maxn+10];
23 int vis[26][26][26][26];
24 
25 
26 void solve()
27 {
28     a[0] = a[1] = a[2] = 0;
29     for(int i = 3; i<maxn+3; i++)
30     {
31         for(int j = 25; j>=0; j--)
32         {
33             if(vis[a[i-3]][a[i-2]][a[i-1]][j]==0)
34             {
35                 vis[a[i-3]][a[i-2]][a[i-1]][j] = 1;
36                 a[i] = j;
37                 break;
38             }
39         }
40     }
41 }
42 
43 int main()
44 {
45     int n;
46     solve();
47     while(scanf("%d",&n)!=EOF)
48     {
49         if(n>maxn+3)
50             printf("Impossible");
51         else
52             for(int i = 0; i<n; i++)
53                 printf("%c",a[i]+'a');
54         putchar('\n');
55     }
56 }
View Code

 


 

posted on 2017-05-31 19:01  h_z_cong  阅读(144)  评论(0编辑  收藏  举报

导航