hdu 4148 Length of S(n)(找规律)
来源:互联网 发布:网络古风翻唱歌手 编辑:程序博客网 时间:2024/06/12 22:11
这题每个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
....
.....
例如:
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<iostream>#include<cstdio>#include<cstring>using namespace std;string s[40];void fun(){ int i,j,k,m; s[0]="1";s[1]="11"; for(i=2;i<=30;i++) { int len=s[i-1].length(); for(m=1,j=1;j<len;j++) { if(s[i-1][j]!=s[i-1][j-1]){ s[i]+=char(m+'0'); s[i]+=s[i-1][j-1]; m=1; }else{ m++; } } if(j==len){ s[i]+=char(m+'0'); s[i]+=s[i-1][j-1]; } //cout<<s[i]<<endl; }}int main(){ int n,i,j; fun(); while(scanf("%d",&n),n) { cout<<s[n-1].length()<<endl; } return 0;}
0 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 找规律
- 一道莫名其妙的华为面试题解法
- EL表达式的简要学习
- 802.11ac路由选购技术攻略
- 编程开发中最浪费时间和资源的7个错误
- 几个名词术语
- hdu 4148 Length of S(n)(找规律)
- HDU 2089 不要62 (数位DP)
- ARM Linux内核驱动异常定位方法分析--反汇编方式
- HDU 1498 50 years, 50 colors
- 最小生成树(削减某条边后该边能否构成最小生成树的成分)
- version `GLIBCXX_3.4.11' not found错误及解决
- 内核Oops小结
- 2013谷歌笔试题
- Java遍历Properties