Ural 2045 Richness of words(构造)
2016-08-07 20:56
1126 查看
045. Richness of words
Time limit: 0.5 secondMemory limit: 64 MB
For each integer i from 1 to n, you must print a stringsi of length
n consisting of lowercase Latin letters.The stringsi must contain exactly
i distinct palindrome substrings.Two substrings are considered distinct if they are different as strings.
Input
The input contains one integer n (1 ≤n ≤ 2000).
Output
You must print n lines. If for somei, the answer exists, print it in the form “i : si” wheresi is one of possible strings.Otherwise, print “i : NO”.
Sample
input | output |
---|---|
4 | 1 : NO 2 : NO 3 : abca 4 : bbca |
#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #include<stack> #include<cmath> #include<queue> #define INF 0x3f3f3f3f #define eps 1e-9 #define MAXN 10005 using namespace std; int n; char s[MAXN]; int main() { scanf("%d",&n); if(n == 1) { cout<<"1 : a"<<endl; return 0; } if(n == 2) { cout<<"1 : NO"<<endl; cout<<"2 : aa"<<endl; return 0; } cout<<"1 : NO"<<endl; cout<<"2 : NO"<<endl; for(int i = 0;i < n;i++) s[i] = 'a' + i % 3; s = '\0'; cout<<"3 : "<<s<<endl; for(int i = 4;i <= n;i++) { s[i-4] = 'd'; cout<<i<<" : "<<s<<endl; } }
相关文章推荐
- Ural 2045 Richness of words
- Timus Online Judge 2045 Richness of words
- URAL 2037 Richness of binary words
- Ural 2037 Richness of binary words
- 30. Substring with Concatenation of All Words
- URAL 1920 Titan Ruins: the Infinite Power of Magic
- leetcode Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- Project 3: Scene recognition with bag of words
- Leetcode: Substring with Concatenation of All Words
- SIFT算法的应用--目标识别之Bag-of-words模型(转)
- Bag-of-words模型
- SIFT算法的应用--目标识别之Bag-of-words模型
- LeetCode 30 - Substring with Concatenation of All Words
- [Leetcode]30. Substring with Concatenation of All Words @python
- LeetCode|Substring with Concatenation of All Words
- using tail recursion to reverse words of line ( just for fun)
- Bag of Words/Bag of Features的Matlab源码发布
- LeetCode_OJ【30】Substring with Concatenation of All Words