hdu 4850 Wow! Such String! 构造 欧拉回路
来源:互联网 发布:淘宝怎么提升排名靠前 编辑:程序博客网 时间:2024/06/06 19:07
Wow! Such String!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 934 Accepted Submission(s): 318
Special Judge
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?
For each test case, there will be one line containing one integer N (1 ≤ N ≤ 500000).
Sum of all N will not exceed 5000000.
5311106178
pwnedwowsuchproblemmanystringsoeasymuchlinearalgebraabcdabch
链接 http://acm.hdu.edu.cn/showproblem.php?pid=4850
题意:输出长度为n,长度为4的子串不能重复出现的 小写字母组成的 字符串。
做法:最大长度为4的字符串一共有 26^4个, 如果他们都能连接 如 aaaa 和aaab 可以连接为 aaaab。 如果能都连接的话,最长 长度为26^4+3= 456979。
构造,先把 相同的 构造好, aaaabbbbccccdddd.....yyyyzzzz。把出现过的存在一个4维数组里 如 aaaa,就把dp[0][0][0][0]=1。 如 aazz 就把dp[0][0][25][25]=1;
然后继续构造下一个字母,从最大的字母开始凑接下来一个字母 z不行,因为四个z已经出现过,所以填入y。
这个是这种方法构造出来的 前面一部分的构造结果。
aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrsssstttt
uuuuvvvvwwwwxxxxyyyyzzzzyzzyyzyzyyyxzzzxzzyxzyzxzyyxyzzxyzyxyyzxyyxxzzxxzyxxyzxx
yxzxzxyxyxxxzxxxwzzzwzzywzzxwzyzwzyywzyxwzxzwzxywzxxwyzzwyzywyzxwyyzwyyywyyxwyxz
wyxywyxxwxzzwxzywxzxwxyzwxyywxyxwxxzwxxywxxwwzzwwzywwzxwwyzwwyywwyxwwxzwwxywwxwz
经常见到的一类构造问题。这种问题普遍就是 要求 构造一段 长度 然后在这个长度内 某长度的子串没有重复出现。
看了题解,知道了这类题的理论基础是欧拉回路。
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <malloc.h>#include <ctype.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#include <stack>#include <queue>#include <vector>#include <deque>#include <set>#include <sstream>#define eps 0.00001#define LL __int64#define pi acos(-1.0)//456979set<string>my;char str[457000];int dp[26][26][26][26];int main(){str[0]=str[1]=str[2]='a';string tem;string mat;memset(str,0,sizeof str);memset(dp,0,sizeof dp);for(int i=0;i<26;i++){for(int j=0;j<4;j++){str[i*4+j]='a'+i; }}for(int i=3;i<26*4;i++){dp[str[i-3]-'a'][str[i-2]-'a'][str[i-1]-'a'][str[i]-'a']=1;}for(int i=26*4;i<456979;i++){ for(int j=25;j>=0;j--){if(dp[str[i-3]-'a'][str[i-2]-'a'][str[i-1]-'a'][j]==0){dp[str[i-3]-'a'][str[i-2]-'a'][str[i-1]-'a'][j]=1;str[i]=j+'a';break;} }}int n;while(scanf("%d",&n)!=EOF){if(n>456979){printf("Impossible");continue;}char tem=str[n];str[n]=0;printf("%s\n",str);str[n]=tem;}return 0;}
- hdu 4850 Wow! Such String! 构造 欧拉回路
- hdu 4850 Wow! Such String! 构造 欧拉回路
- hdu 4850 Wow! Such String!(欧拉回路)
- HDU 4850 Wow! Such String! 欧拉回路
- HDU 4850 Wow! Such String!(欧拉道路)
- HDU 4850 Wow! Such String! 欧拉路径
- HDU-4850 Wow! Such String! (构造)
- 构造字符串 之 hdu 4850 Wow! Such String!
- HDU 4850 Wow! Such String!(构造推理)
- 【HDU】4850 Wow! Such String! 提出猜想题 欧拉道路
- HDU 4850 2014西安邀请赛 D题 Wow! Such String!
- 【HDU】4850 Wow! Such String! 提出猜想题
- hdu 4850 Wow! Such String! 2014西安全国邀请赛
- hdu 4850 字符串构造---欧拉回路构造序列 递归+非递归实现
- HDU 欧拉回路
- 欧拉回路 HDU
- HDU 欧拉回路
- HDU4850 Wow! Such String! —— 字符串构造
- POJ 2187 Beauty Contest(凸包:最远点对距离)
- pat1010
- 1277 字符串中的最大值 next数组的妙用
- CSS的长度、角度、时间
- Python量化交易talib中SMA模块介绍
- hdu 4850 Wow! Such String! 构造 欧拉回路
- Android系统权限说明
- leetcode改进 Reverse Pairs
- struts2框架搭建开发环境
- 2017 ACM/ICPC Asia Regional Shenyang Online 1001(hdu 6194)
- PAT练习(4)-1044 Table Tennis (30)
- [LeetCode]169.Majority Element
- Unity3D 设计模式---策略模式
- 轮播图Banner使用