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种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...
随机推荐
- virtualbox cannot access the kernel driver的解决办法
一位网友windows xp sp3下安装virtualbox 4.1.20版本,安装好了重启过后,可以打开virtualbox,但是等到创建好虚拟电脑后按启动按钮,就出现了错误提示:"Ca ...
- windows phone 新手引导
说到windows phone 新手这个问题,当初我们纠结了很久,网上大致有两种解决方案:一种是通过动画的方式:另一种简单的方式就是通过pivot 在第一种方式里面我们的实现思路就是监测手势的滑动方向 ...
- android开发中经常遇到的问题汇总
大家都在为项目开发成功而喜悦,但可不知成功的路上是会经常出错的,下面是我碰到的一些错误集合! [错误信息] [2011-01-19 16:39:10 - ApiDemos] WARNING: Appl ...
- c/c++常用代码 -- 共享内存
#pragma once #include <stdio.h> #include <tchar.h> #include <string.h> #include &l ...
- Python实现kMeans(k均值聚类)
Python实现kMeans(k均值聚类) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=> ...
- Windows Live Writer教程及代码高亮工具
十分感谢六仙庵对于Windows Live Writer的教程,方便了编辑与发布,教程地址如下: http://www.cnblogs.com/liuxianan/archive/2013/04/13 ...
- cacti install on ubuntu
安装cacti需要的软件需要 nginx + php + mysql + rrdtool + cacti + snmp 1.nginx 安装配置 首先按照如下命令安装,明显是马虎不细心./config ...
- Careercup - Microsoft面试题 - 5943729928011776
2014-05-10 21:56 题目链接 原题: Suppose you get number of unique users every second from bing For eg, ,,,, ...
- adb怎么判断是否有root权限,并更改system/app内容
一.首先判断root权限: adb root 结果: C:\signapp>adb root restarting adbd as root # 说明有root权限 ,若是adbd cannot ...
- 【Binary Tree Maximum Path Sum】cpp
题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tr ...