hdu 1865 1sting

高精度

斐波那契数

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int L=110;
string add(string a,string b)//只限两个非负整数相加
{
    string ans;
    int na[L]={0},nb[L]={0};
    int la=a.size(),lb=b.size();
    for(int i=0;i<la;i++) na[la-1-i]=a[i]-'0';
    for(int i=0;i<lb;i++) nb[lb-1-i]=b[i]-'0';
    int lmax=la>lb?la:lb;
    for(int i=0;i<lmax;i++) na[i]+=nb[i],na[i+1]+=na[i]/10,na[i]%=10;
    if(na[lmax]) lmax++;
    for(int i=lmax-1;i>=0;i--) ans+=na[i]+'0';
    return ans;
}
string dp[200+5];
int main()
{
    dp[1]="1";
    dp[2]="2";
    for(int i=3;i<205;i++) dp[i]=add(dp[i-1],dp[i-2]);
    string x;
    int t;
    cin>>t;
    while(t--)
    {
    	cin>>x;
    	cout<<dp[x.size()]<<endl;
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-08 01:05:05

hdu 1865 1sting的相关文章

HDU 1865 1sting (递推、大数)

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7573    Accepted Submission(s): 2945 Problem Description You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’

HDUJ 1865 1sting

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3227    Accepted Submission(s): 1237 Problem Description You will be given a string which only contains '1'; You can merge two adjacent '1

HDU 1865

1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3200    Accepted Submission(s): 1230 Problem Description You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’

高精度题目列表

JAVA大数类练手 748 - Exponentiation Uva 424 Uva 10106 Uva 465 Uva 10494 POJ 2389 POJ 2756 HDU 1715 HDU 1047 HDU 1297 HDU 1002 HDU 1316 HDU 1865 HDU 1250 HDU 1042 HDU 1753 POJ 1220 HDU 2100 Uva 10023 Uva 10069 HDU 4762 Uva 10497 Uva 10844 HDU 4873 Uva 1478

Java大数练习第二弹

hdu1250 水题 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 import java.util.*; import java.math.BigInteger; public class Main{ public static void main(String[] args){ int a; Scanner in=new Scanner(System.in); while(in.hasNext()){ a=in.nextInt();

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

hdu 1250 Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9677 Accepted Submission(s): 3210 Problem Description A Fibonacci sequence is calculated by adding the previous two members the seque

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201