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. Tornado之抽屉实战(1)--分析与架构

    项目模拟地址:http://dig.chouti.com/ 知识点应用: AJAX  用于偷偷发请求 原生ajax jQuery  ajax($.ajax) iframe伪造 上传文件 传统Form ...

  2. Ros学习——Python发布器publisher和订阅器subscriber

    1.编写发布器 初始化 ROS 系统 在 ROS 网络内广播我们将要在 chatter 话题上发布 std_msgs/String 类型的消息 以每秒 10 次的频率在 chatter 上发布消息 在 ...

  3. SpringBoot04 日志框架之Logback

    1 日志框架选择 日志门面:SLF4J 日志实现:Logback 2 实现控制台的日志打印输出01 2.1 在需要实现日志信息打印的类中实例化Logger对象 坑01:springBoot项目默认使用 ...

  4. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-001选择排序法(Selection sort)

    一.介绍 1.算法的时间和空间间复杂度 2.特点 Running time is insensitive to input. The process of finding the smallest i ...

  5. python3-list列表增删改查合并排序

    # Auther: Aaron Fan names = ["aaron", "alex", "james", "meihengfa ...

  6. SDUT 1488 数据结构实验:连通分量个数

    数据结构实验:连通分量个数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description  在无向图中,如 ...

  7. Java 深入变量和封装思想小结

    1.变量的分类和初始值 成员变量:有初始值 局部变量:没有初始值 2.类字段 static :存在于方法区里面 实例变量(实例字段):存在于堆里面 局部变量:存在于栈里面 方法的覆盖: 子类覆盖父类: ...

  8. HTTP 协议 -- 浏览器缓存机制

    浏览器缓存机制 浏览器缓存机制主要是 HTTP 协议定义的缓存机制. HTTP 协议中有关缓存的缓存信息头的关键字有 Cache-Control,Pragma,Expires,Last-Modifie ...

  9. EF中的MySql返回 DataTable公共类库

    public static class SqlHelper { /// <summary> /// EF SQL 语句返回 dataTable /// </summary> / ...

  10. CHImage

    1.启动图.图标 iOS应用图片尺寸制作脚本 ======= github 规格尺寸(官方) AppIcon应用图标 and Launchimage启动图标的制作 iPhone所有手机型号屏幕尺寸 2 ...