日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU-4850 Wow! Such String!(模拟) ——26行代码AC

發布時間:2024/2/28 编程问答 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU-4850 Wow! Such String!(模拟) ——26行代码AC 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

立志用更少的代碼做更高效的表達


Recently, doge starts to get interested in a strange problem: whether there exists a string A following all the rules below:

1.The length of the string A is N .
2.The string A contains only lowercase English alphabet letters.
3.Each substring of A with length equal to or larger than 4 can appear in the string exactly once.

Doge cannot solve the problem, so he turns to his brother Yuege for help. However, Yuege is busy setting problems. Would you please help doge solve this problem?

Input

There are several test cases, please process till EOF.
For each test case, there will be one line containing one integer N (1 ≤ N ≤ 500000).
Sum of all N will not exceed 5000000.

Output

For each case, please output one line consisting a valid string if such a string exists, or “Impossible” (without quotes) otherwise. You can output any string if there are multiple valid ones.

Sample Input

5
3
11
10
6
17
8

Sample Output

pwned
wow
suchproblem
manystring
soeasy
muchlinearalgebra
abcdabch


題意

給你一個整數n,讓你輸出一個字符串。必須滿足以下條件:

1.字符串的長度為n。

2.這個字符串只包含小寫字母。

3.字符串中長度大于等于4的子串最多只能出現一次。

如果無解輸出Impossible。


解題思路

因為大于等于4的子串只能出現一次,所以不會重復的串最長只會達到4^26+3 = 456979的長度。

因此, 我們可以預先打一個不會重復的字符表出來

若n>456979 ,則輸出Impossible。

否則輸出表的前n項。

打表的方式用循環即可。


代碼解析

#include<iostream> using namespace std; int vis[26][26][26][26]; int s[5000005]; int main() {ios::sync_with_stdio;for(int i = 0; i < 26; i++) s[i*4] = s[i*4+1] = s[i*4+2] = s[i*4+3] = i;for(int i = 3; i < 26*4; i++) vis[s[i-3]][s[i-2]][s[i-1]][s[i]]=1;for(int i=26*4; i < 456979; i++) //xxfor(int j = 25; j >= 0; j--) if(vis[s[i-3]][s[i-2]][s[i-1]][j]==0) {vis[s[i-3]][s[i-2]][s[i-1]][j]=1;s[i] = j;break;}int n; while(cin>>n) {if(n > 456979) { cout << "Impossible" << '\n'; }else {for(int i = 0; i < n; i++) putchar(s[i]+97);putchar('\n');}}return 0; }

總結

以上是生活随笔為你收集整理的HDU-4850 Wow! Such String!(模拟) ——26行代码AC的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。