Length of S(n) hdu4148 水题
来源:互联网 发布:镜片清洗液 知乎 编辑:程序博客网 时间:2024/06/06 15:40
http://acm.hdu.edu.cn/showproblem.php?pid=4148
此题的规律就是……
s(1)=1
s(2)=11 (表示s(1)有1个1)
s(3)=21(表示s(2)有2个1)
s(4)=1211(表示s(3)有1个2,1个1)
……
#include <iostream>#include <string>using namespace std;#define N 31string s[N];void init(){ //初始化,按规律写出30个串。s[0]="1";int i,j,k;char c;for (i=1;i<N;i++){s[i]="";c=s[i-1][0]; //表示数字k=1; //统计个数for (j=1;j<s[i-1].length();j++){if (c!=s[i-1][j]){ //遇到不一样的数字时就添加s[i].append(1,k+48); //先将个数加进去s[i].append(1,c); //再加数字k=1;c=s[i-1][j];}else k++; //一样时,个数加加。}s[i].append(1,k+48);s[i].append(1,c);}}int main(){#ifndef ONLINE_JUDGEfreopen("Fin.txt","r",stdin);#endifint n;init();while (scanf("%d",&n)!=EOF&&n)printf("%d\n",s[n-1].length());return 0;}
- Length of S(n) hdu4148 水题
- Length of S(n) hdu4148 水题
- ACM Length of S(n)
- 杭电4148-Length of S(n)
- 102.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) 【找规律+字符串】
- HDU 4148 Length of S(n)(规律题)
- hdoj 4148 Length of S(n) 【打表】
- HDU 4148Length of S(n)(兴爷版)
- hdu4148
- 2011百校联动“菜鸟杯”程序设计公开赛&&Length of S(n)
- Distinct binary strings of length n with no consecutive 1s
- LeetCode-58-Length of Last Word 水题
- CareerCup Output the amount of all possible strings of length N that don't of have consecutive a,b,c
- 69. Sqrt(x)\58. Length of Last Word\50. Pow(x, n)
- 分布式协调器ZooKeeper3.4—入门
- Linux C语言内联汇编使用 .
- 分享:某类程序不支持64位的程序在win2008R2与IIS7.5上运行的问题的解决方法
- Commons Io 包 学习笔记~
- python中列表(list)和字典(dict)数据排序
- Length of S(n) hdu4148 水题
- 在服务器上处理请求时出现未知错误。服务器返回的状态码为500。的处理方法。
- 连接不上sql server
- Teradata数据库复制表
- 开源Commons包的 使用粗劣总结~
- android联系人ListView布局效果
- oracle在已有重复数据的列上创建唯一约束
- 逐浪CMS5.0新版模板精彩亮相
- 引用计数需要注意的几个地方