首页 > 其他分享 >HDU-1865-1sting

HDU-1865-1sting

时间:2023-02-02 11:37:28浏览次数:47  
标签:HDU get int number len 斐波 1sting num 1865


1sting

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3997 Accepted Submission(s): 1489

Problem Description
You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.

Input
The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.

Output
The output contain n lines, each line output the number of result you can get .

Sample Input
3
1
11
11111

Sample Output
1
2
8

​题目链接​

#include<stdio.h>
#include<string.h>
char s[210];
int num[210][1000];
int len[1000];
int main()
{
int n;
int i,j,k,l,m;
memset(num,0,sizeof(num));//二维数组也可以这样初始化
num[1][0]=1;
num[2][0]=2;//初始斐波那契数前两位
len[1]=len[2]=1;//储存大数的位数
l=0;
for(i=3;i<210;i++)
{
k=0;
for(j=0;j<=len[i-1];j++)
{
l=k+num[i-1][j]+num[i-2][j];
num[i][j]=l%10;
k=l/10;
} //用第一维储存斐波那契数第二维储存位数(如果你先把大数相加就是杭电1002和大数相乘1042做过之后这里就很好理解啦)
if(num[i][len[i-1]]!=0)
len[i]=len[i-1]+1;
else
len[i]=len[i-1];//此处是标记第一个非零数的位置(就是去零)
}
scanf("%d",&n);
getchar();
while(n--)
{
//getchar();
scanf("%s",s);
m=strlen(s);
for(i=len[m]-1;i>=0;i--)
printf("%d",num[m][i]);
printf("\n");
}
return 0;
}

题目总结: 此题是斐波那契数列与大数相加的结合,此解法是利用二维数组对数据进行处理
num[m][i] 第一维 m 是表示第几个斐波那契数 第二维 i 是表是第 m 个数的位数


标签:HDU,get,int,number,len,斐波,1sting,num,1865
From: https://blog.51cto.com/u_14235050/6033405

相关文章

  • HDU-1286-找新朋友
    ​​题目链接​​找新朋友TimeLimit:2000/1000ms(Java/Other)MemoryLimit:65536/32768K(Java/Other)TotalSubmission(s):5AcceptedSubmission(s):2Font......
  • HDU-2089-不要62
    ​​点这里查看题目​​#include<stdio.h>#definemaxn1000010intf[maxn];intweishu(inta){intb=1;while(1){if(a/10==0)break;......
  • HDU-1251-统计难题(未完待续 还有两种方法还没整理)
    统计难题统计难题TimeLimit:4000/2000MS(Java/Others)MemoryLimit:131070/65535K(Java/Others)TotalSubmission(s):22667AcceptedSubmission(s):9545Proble......
  • hdu:Two Rabbits(区间DP)
    ProblemDescriptionLonglongago,therelivedtworabbitsTomandJerryintheforest.Onasunnyafternoon,theyplannedtoplayagamewithsomestones.Th......
  • LCM Walk HDU - 5584
    https://vjudge.net/problem/HDU-5584题意:(x,y)可以走到(x+lcm(x,y),y),或(x,y+lcm(x,y))给定终点(ex,ey),问从起点到终点走了多少步?解:先按照题意模拟:设d=gcd(x,y),则再设......
  • hdu: 改革春风吹满地(叉乘求面积)
    ProblemDescription“改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地。谢谢!(乐队奏乐)”话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是......
  • hdu:Shape of HDU(判断多边形凹凸)
    ProblemDescription话说上回讲到海东集团推选老总的事情,最终的结果是XHD以微弱优势当选,从此以后,“徐队”的称呼逐渐被“徐总”所取代,海东集团(HDU)也算是名副其实了。创业......
  • hdu:"红色病毒"问题(指数型母函数用e^x指数函数来计算)
    ProblemDescription医学界发现的新病毒因其蔓延速度和Internet上传播的”红色病毒”不相上下,被称为”红色病毒”,经研究发现,该病毒及其变种的DNA的一条单链中,胞嘧啶,......
  • hdu:The Balance(母函数)
    ProblemDescriptionNowyouareaskedtomeasureadoseofmedicinewithabalanceandanumberofweights.Certainlyitisnotalwaysachievable.Soyoushou......
  • hdu4135
    求[a,b]中与n互素的数字个数  #include<iostream>#include<algorithm>usingnamespacestd;constintN=200;#defineintlonglonginttot,fac[N];......