hdu 4148 Length of S(n) --字符串找规律
来源:互联网 发布:快捷混合矩阵 编辑:程序博客网 时间:2024/05/21 14:44
题目:
S(1)=1,
S(2)=11,S(3)=21,
S(4)=1211,
S(5)=111221,
S(6)=312211,
....
求S(n)的长度。
思路:
题目很简单就是压缩字符串, 比如:s[4] = 1211 那么是s[5]中内容就是1一个1即11, 一个2即12和2个1即21, 合起来s[5]就是11 12 21
同理s[5] = 111221 那么s[6]就是3个1即31, 2个2即22, 1个1即11合起来就是31 22 11;
代码如下
#include <iostream>using namespace std;#define N 5000char str[31][N];void init(){int i, j, count, k, n;memset(str, 0, sizeof(str));str[1][0] = '1';str[2][0] = '1';str[2][1] = '1';for (i = 3;i <= 30 ; ++i){k = 0;n = strlen(str[i - 1]);count = 1;for (j = 0; j < n; ++j){if (str[i - 1][j] == str[i - 1][j + 1]){++count;}else{while(count){str[i][k++] = count % 10 + '0';count /= 10;}str[i][k++] = str[i - 1][j];count = 1;}}}}int main(){int n;init();while(scanf("%d", &n) != EOF && n){int len = strlen(str[n]);printf("%d\n", len);}return 0;}
- hdu 4148 Length of S(n) --字符串找规律
- HDU 4148 Length of S(n) 【找规律+字符串】
- HDU 4148 Length of S(n)(找规律)
- hdu 4148 Length of S(n)(找规律)
- HDU 4148 Length of S(n)(规律题)
- 102.hdu--4148--Length of S(n)
- HDU 4148Length of S(n)(兴爷版)
- 杭电4148-Length of S(n)
- ACM Length of S(n)
- hdoj 4148 Length of S(n) 【打表】
- hdu 2114 Calculate S(n)(找规律的题目,比赛的时候没做出来)
- hdu 2674 N!Again(找规律)
- hdu 5601 N*M bulbs 找规律
- hdu 2674 n!余数 (找规律)
- HDU 6043 KazaQ's Socks 找规律
- HDU 6154 CaoHaha's staff 找规律
- HDU 6154 CaoHaha's staff【找规律】
- HDU 6154 CaoHaha's staff 找规律
- 百度后台开发类笔试题2014校园招聘 武汉站
- 改变eclipse字体、背景颜色
- poj3461 kmp模板题
- centos安装vim7.4
- POJ 1182并查集的经典运用
- hdu 4148 Length of S(n) --字符串找规律
- sdutoj 1027 生日蛋糕 和 poj 1190
- lua_touserdata返回值详释
- Hive优化总结
- Android之SurfaceView
- 网络子系统28_桥接ioctl
- 奇虎360 -- 2013年校园招聘技术类笔试题
- 说说SEO优化最好最全的干货:十大点经验分享
- 奇虎360笔试解答