1sting

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

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
 
输出的结果巨长,远超出一般的数据范围^v^
 
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int a[][];//因为是大数,一维数组并不能储存数字,所以用二维,后面用来分别储存大数的每个位数
int main()
{
int n,t;
int r,s,i;
r=;
memset(a,,sizeof(a));
a[][]=;
a[][]=;
for(i=;i<=;i++)//大数的加法
{
for(int j=;j<=;j++)//底位在数组前面,高位存在数组后面
{
s=a[i][j]+a[i+][j]+r;
a[i+][j]=s%;
r=s/;
}
}
scanf("%d",&t);
while(t--)
{
char str[];
cin>>str;
n=strlen(str);
if(n==)
printf("1\n");
else if(n==)
printf("2\n");
else
{
for(i=;i>=;i--)//从高位开始输出
if(a[n][i])
break; //当a[n][i]为0时跳出,此时的i即答案有几位数,进入下一步的输出
for(;i>=;i--)
printf("%d",a[n][i]);
printf("\n");
}
}
return ;
}

相同的题目:hdu5686

Problem B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1615    Accepted Submission(s): 665

Problem Description
  度熊面前有一个全是由1构成的字符串,被称为全1序列。你可以合并任意相邻的两个1,从而形成一个新的序列。对于给定的一个全1序列,请计算根据以上方法,可以构成多少种不同的序列。
 
Input
这里包括多组测试数据,每组测试数据包含一个正整数N,代表全1序列的长度。

1≤N≤200

 
Output
对于每组测试数据,输出一个整数,代表由题目中所给定的全1序列所能形成的新序列的数量。
 
Sample Input
1
3
5
 
Sample Output
1
3
8

Hint

如果序列是:(111)。可以构造出如下三个新序列:(111), (21), (12)。

 
 
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int a[][];//因为是大数,一维数组并不能储存数字,所以用二维,后面用来分别储存大数的每个位数
int main()
{
int n;
int r,s,i;
r=;
memset(a,,sizeof(a));
a[][]=;
a[][]=;
for(i=;i<=;i++)//大数的加法
{
for(int j=;j<=;j++)//底位在数组前面,高位存在数组后面
{
s=a[i][j]+a[i+][j]+r;
a[i+][j]=s%;
r=s/;
}
}
while( cin>>n)
{
if(n==)
printf("1\n");
else if(n==)
printf("2\n");
else
{
for(i=;i>=;i--)//从高位开始输出
if(a[n][i])
break; //当a[n][i]为0时跳出,此时的i即答案有几位数,进入下一步的输出
for(;i>=;i--)
printf("%d",a[n][i]);
printf("\n");
}
}
return ;
}

hdu1865 1sting (递归+大数加法)的更多相关文章

  1. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

  2. c#大数加法

    在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...

  3. 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)

    题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...

  4. Leetcode 67 Add Binary 大数加法+字符串处理

    题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...

  5. HDU1002大数加法

    大数加法 c++版: #include <map> #include <set> #include <stack> #include <queue> # ...

  6. java实现大数加法、乘法(BigDecimal)

    之前写过用vector.string实现大数加法,现在用java的BigDecimal类,代码简单很多.但是在online-judge上,java的代码运行时间和内存大得多. java大数加法:求a+ ...

  7. vector、string实现大数加法乘法

    理解 vector 是一个容器,是一个数据集,里边装了很多个元素.与数组最大的不同是 vector 可以动态增长. 用 vector 实现大数运算的关键是,以 string 的方式读入一个大数,然后将 ...

  8. 【大数加法】POJ-1503、NYOJ-103

    1503:Integer Inquiry 总时间限制:  1000ms 内存限制:  65536kB 描述 One of the first users of BIT's new supercompu ...

  9. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

随机推荐

  1. 第四天:servlet的生命周期和一些细节问题

    1.  servlet的生命周期: a)  流程 i.  Web服务器首先会检查是否装载了该servlet的实例对象.如果装载了直接进行第四步. ii.  装载并创建该servlet的实例对象. ii ...

  2. POJ 3714 分治/求平面最近点对

    第一次见这种问题直接懵圈...没想到分治法这么强大,借鉴了lyd的代码: 代码如下 #include<cstdio> #include<algorithm> #include& ...

  3. 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-003定理

    1. 2. 3. 4. 5. 6.

  4. 算法Sedgewick第四版-第1章基础-014一用stack把前置表达式转为后置表达式并计算值

    1. /************************************************************************* * Exercise 1.3.10 * * ...

  5. hive的not in

    最近项目需要对数据做打平操作,原有的sql使用了not in,但是hive 不支持 not in,晚上搜索了下使用 left outer join select * from lefttbl a le ...

  6. kaggle Partial_Dependence_Plots

    # Partial dependence plots# 改变单变量对最终预测结果的影响# 先fit出一种模型,然后取一行,不断改变某一特征,看它对最终结果的印象.# 但是,只使用一行不具有典型性# 所 ...

  7. 遍历一个二维数组的简便方法(减少foreach次数)

    在一些特定场合可以使用下, 还是有局限性 输出结果 : 另一种场景 : 输出结果 : 更复杂的场景 : 输出结果 :

  8. 双击获取GridView控件行信息

    有网友要求在GridView控件上,不管是单击(onclick)还是双击(ondblclick),想获取所击行的信息.技术难度是为GridView的行注册单击或是双击事件.看例子吧:在数据库中创建数据 ...

  9. Data Base mysql批量操作

    mysql  批量操作 批量操作数据是利用 CommandBuilder  和 DataAdapter.Update() 方法 对数据库进行批量更新 说解: DataAdapter中有四个重要对象:S ...

  10. Redis源码阅读---连接建立

    对于并发请求很高的生产环境,单个Redis满足不了性能要求,通常都会配置Redis集群来提高服务性能.3.0之后的Redis支持了集群模式. Redis官方提供的集群功能是无中心的,命令请求可以发送到 ...