http://acm.hdu.edu.cn/showproblem.php?pid=4850

西安邀请赛当时没做出来的银牌门坎题

题意:构造一个长度n的字符串,长度>=4的子串只能出现一次

题解:暴力枚举构造,复杂度是O(最长字符串长度*26),注意到最长字符串长度是26^4+3,因为长度为4的字符串共有26^4种,每种占一个起点,最后加3。注意暴力构造时aaaa,bbbb这种不会被构造出来,要提前加上

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std ; int ans[] ;
int vis[][][][] ; int main()
{
int n ;
int len= ;
int OK= ;
for(int i= ;i< ;i++)
for(int j= ;j< ;j++)
ans[len++]=i ;
for(int i= ;i<len- ;i++)
vis[ans[i]][ans[i+]][ans[i+]][ans[i+]]= ;
while(OK)
{
OK= ;
for(int i= ;i< ;i++)
{
if(!vis[ans[len-]][ans[len-]][ans[len-]][i])
{
vis[ans[len-]][ans[len-]][ans[len-]][i]= ;
ans[len++]=i ;
OK= ;
}
}
}
while(~scanf("%d",&n))
{
if(n>len)puts("Impossible") ;
else
{
for(int i= ;i<n ;i++)
printf("%c",ans[i]+'a') ;
putchar('\n') ;
}
}
return ;
}

HDU 4850的更多相关文章

  1. hdu 4850 Wow! Such String! 欧拉回路

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...

  2. HDU 4850 Wow! Such String!(欧拉道路)

    HDU 4850 Wow! Such String! 题目链接 题意:求50W内的字符串.要求长度大于等于4的子串,仅仅出现一次 思路:须要推理.考虑4个字母的字符串,一共同拥有26^4种,这些由这些 ...

  3. HDU 4850 Wow! Such String!

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4850 题意:给定一个N(1 ≤ N ≤ 500000),构造一个长度为N的小写字母字符串,要求所有长度大于 ...

  4. hdu 4850 字符串构造---欧拉回路构造序列 递归+非递归实现

    http://acm.hdu.edu.cn/showproblem.php? pid=4850 题意:构造长度为n的字符序列.使得>=4的子串仅仅出现一次 事实上最长仅仅能构造出来26^4+4- ...

  5. hdu 4850 Wow! Such String!(字符串处理,yy)

    题目 参考了博客http://blog.csdn.net/u013368721/article/details/37575165 //用visit[26][26][26][26]来判断新家新区的子母河 ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. Firefox火狐Flash插件卡死问题完美解决方法(转载)

    http://www.ihacksoft.com/firefox-flash-protectedmode.html 其实这个问题以前就出现过,而最近该问题又出现在最新的 Windows 8.1 系统中 ...

  2. poj1651

    Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7252   Accepted:  ...

  3. JSP中,当页面为404或者500时。设置跳转到错误提示页面

    最好的就是在WEB.XML文件中配置错误代码的跳转页面,首先建立个 出现500错误的页面,提示出错了,然后再WEB.XML文件中配置,配置如下 一. 通过错误码来配置error-page <er ...

  4. php -l 检查文件是否语法错误

    有时候在进行网页开发的时候,后台文件的语法错误比较难检查出来,这时候使用php -l filename可对文件的语法进行检查.

  5. C#常用的加密算法

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 方法一:     //须添加对System.Web的引用    ...

  6. JBoss JMX登录需要用户名密码的解决办法

    /opt/jboss/eap5.1.2/jboss-as/server/default/conf/props/jmx-console-users.properties 取消#admin=admin的注 ...

  7. Ganglia监控Hadoop集群的安装部署[转]

    Ganglia监控Hadoop集群的安装部署 一. 安装环境 Ubuntu server 12.04 安装gmetad的机器:192.168.52.105 安装gmond的机 器:192.168.52 ...

  8. 如何在datagridview 的head上绘制一个全选按钮

    winform的项目中,经常要用到datagridview控件,但是为控件添加DataGridViewCheckBoxColumn来实现数据行选择这个功能的时候,经常需要提供全选反选功能,如果不重绘控 ...

  9. Codeforces 417E

    #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...

  10. bzoj 2245: [SDOI2011]工作安排

    #include<cstdio> #include<iostream> #include<cstring> #define M 10000 #define inf ...