HDU 4148 Length of S(n)(字符串)
字符串处理
题意要猜,解析见代码:
/*
这题每个S(n)是描述S(n-1)值
例如:
S(1)=1;
S(2)=11;即描述S(1)有1个1=11
S(3)=21;即描述S(2)有2个1=21
S(4)=1211;即描述S(3)有1个2和2个1=1211
....
*/ #include <cstdio>
#include<iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct tt
{
int nu[];
int n;
}a[]; int main() {
a[].n=;
a[].nu[]=;
for(int i=;i<;i++){
int num=,pre=a[i-].nu[],idd=;
for(int j=;j<a[i-].n;j++){
if(pre!=a[i-].nu[j]){ int tep[],id=;
while(num!=){
tep[id++]=num%;
num=num/;
}
for(int ii=id-;ii>=;ii--){
a[i].nu[idd++]=tep[ii];
}
a[i].nu[idd++]=a[i-].nu[j-];
num=;
pre=a[i-].nu[j];
}
else {
num++;
}
}
int tep[],id=;
while(num!=){
tep[id++]=num%;
num=num/;
}
for(int ii=id-;ii>=;ii--){
a[i].nu[idd++]=tep[ii];
}
a[i].nu[idd++]=a[i-].nu[a[i-].n-];
a[i].n=idd;
}
int n;
while(scanf("%d",&n),n)
{
cout << a[n].n <<endl;
}
return ;
}
HDU 4148 Length of S(n)(字符串)的更多相关文章
- HDU 2087 剪花布条 (字符串哈希)
http://acm.hdu.edu.cn/showproblem.php?pid=2087 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图 ...
- [LeetCode] Encode String with Shortest Length 最短长度编码字符串
Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...
- HDU 11488 Hyper Prefix Sets (字符串-Trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
- hdu 5469 Antonidas(树的分治+字符串hashOR搜索+剪枝)
题目链接:hdu 5469 Antonidas 题意: 给你一颗树,每个节点有一个字符,现在给你一个字符串S,问你是否能在树上找到两个节点u,v,使得u到v的最短路径构成的字符串恰好为S. 题解: 这 ...
- 【LeetCode每天一题】Length of Last Word(字符串中最后一个单词的长度)
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- HDU 5442 后缀自动机(从环字符串选定一个位置 , 时针或顺时针走一遍,希望得到字典序最大)
http://acm.hdu.edu.cn/showproblem.php?pid=5442 题目大意: 给定一个字符串,可理解成环,然后选定一位置,逆时针或顺时针走一遍,希望得到字典序最大,如果同样 ...
- 题解报告:hdu 1230 火星A+B(字符串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1230 Problem Description 读入两个不超过25位的火星正整数A和B,计算A+B.需要 ...
- hdu 2072 1106学一波字符串分割,C语言与C++两种方法
hdu2072:题意:输出给定字符串中的单词数(一个句子中可能有两个相同的单词),这里的思想是把每个单词取出来,放入set(这个集合容器中不允许有相同的元素)中,最后输出该集合的大小即可. 现在的问题 ...
- HDU 1880 魔咒词典(字符串哈希)
题目链接 Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...
随机推荐
- 【转载/修改】ScrollLayout代码修正,追加模仿viewpager滚动速度
组件作用为类似ViewPager但直接插视图的横向滚动容器. 修改自:http://blog.csdn.net/yaoyeyzq/article/details/7571940 在该组件基础上修正了滚 ...
- Python数学运算
python中的加减乘除比其他的语言简单,不需要对其赋值变量 (1)加减乘除 ) #加法 ) #减法 ) #乘法 ) #除法 5.0 ) #乘方 (2)判断 判断返回的是True或者False ) # ...
- android线程间通讯
近来找了一些关于android线程间通信的资料,整理学习了一下,并制作了一个简单的例子. andriod提供了 Handler 和 Looper 来满足线程间的通信.例如一个子线程从网络上下载了一副图 ...
- 使用ViewSwitcher和ViewFlipper在不同布局中切换
xml布局: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:androi ...
- UIButton之Block回调
本文主要介绍了两种改写UIButton的点击事件方法——继承UIButton跟给UIButton添加一个分类.附代码 方法一:继承UIButton UIButtonBlock.h文件 如下 #impo ...
- Client–server model
Client–server model From Wikipedia, the free encyclopedia The client–server model of computing ] Oft ...
- Swift global function(count indexOfObject contains...)
当你在使用Swift时会发现一些常用的函数不!见!了! 比如 String: s.count() s.contains() Array: a.indexOfObeject(t:<T> ...
- WIN7笔记本利用命令AP热点
第一步:以管理员身份运行命令提示符:开始”---搜索栏输入“cmd----右键以“管理员身份运行”自己随便命名,第二步:运行命令:netsh wlan set hostednetwork mode=a ...
- Indigo Studio
http://www.infragistics.com/products/indigo-studio?gclid=CIXrnav4lcQCFdclvQoduVEAnA
- 玩耍Hibernate之缓存
2.在持久化层,对象分为哪些状态?分别列出来. 答:瞬时态(Transient).持久态(Persistent).脱管态(Detached). 瞬时态(Transient) 是对象是创建时,瞬时对象在 ...