http://acm.hdu.edu.cn/showproblem.php?pid=1715

模板大数:

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <ctype.h>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <utility>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <iostream>
#include <fstream>
#include <list>
using namespace std; const int MAXL = ;
struct BigNum
{
int num[MAXL];
int len;
BigNum()
{
memset(num,,sizeof(num));
}
}; //高精度加法
BigNum Add(BigNum &a, BigNum &b)
{
BigNum c;
int i, len;
len = (a.len > b.len) ? a.len : b.len;
memset(c.num, , sizeof(c.num));
for(i = ; i < len; i++)
{
c.num[i] += (a.num[i]+b.num[i]);
if(c.num[i] >= )
{
c.num[i+]++;
c.num[i] -= ;
}
}
if(c.num[len])
len++;
c.len = len;
return c;
}
void print(BigNum &a) //输出大数
{
int i;
for(i = a.len-; i >= ; i--)
printf("%d", a.num[i]);
puts("");
}
//将字符串转为大数存在BigNum结构体里面
BigNum ToNum(char *s)
{
int i, j;
BigNum a;
a.len = strlen(s);
for(i = , j = a.len-; s[i] != '\0'; i++, j--)
a.num[i] = s[j]-'';
return a;
} void Init(BigNum &a, char *s, int &tag) //将字符串转化为大数
{
int i = , j = strlen(s);
if(s[] == '-')
{
j--;
i++;
tag *= -;
}
a.len = j;
for(; s[i] != '\0'; i++, j--)
a.num[j-] = s[i]-'';
}
BigNum p[];
void deal()
{
int tag=;
Init(p[],"",tag);
Init(p[],"",tag);
for(int i=;i<=;i++)
{
p[i]=Add(p[i-],p[i-]);
}
}
int main(void)
{
//freopen("in.txt","r",stdin);
deal();
int n;
scanf("%d",&n);
while(n--)
{
int t;
scanf("%d",&t);
print(p[t]);
}
return ;
}

hdu1715的更多相关文章

  1. hdu1715(Java)大数相加

    大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  2. hdu1715 大菲波数

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1715 Problem ...

  3. 大菲波数(Fibonacci)java大数(hdu1715)

    大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  4. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

  5. 杭电 OJ 提交代码需要注意的问题

    杭电acm 提交代码需要注意的问题 1. 用 Java 的时候类名请用 Main 2. Java 提交出现 PE 的可能原因有 1) 最基本的错误是空格问题,比如注意每行的末尾是否输出空格 2) 用 ...

  6. 大数问题,通常用JAVA

    e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...

  7. Java大数练习第二弹

    hdu1250 水题 题目链接:pid=1250">http://acm.hdu.edu.cn/showproblem.php?pid=1250 import java.util.*; ...

随机推荐

  1. 5 给我们的c#程序添加注释

    注释是你的程序中的一个重要部分.在程序中添加注释是用来告诉你和其他人你的程序是做什么用的,你的思路是怎样的.注释可以用你熟悉的中文进行添加. 当你想暂时把你程序中的某些语句去掉的时候,不需要把他们删除 ...

  2. 代码实现Autolayout

    代码实现Autolayout的步骤 利用NSLayoutConstraint类创建具体的约束对象 添加约束对象到相应的view上 - (void)addConstraint:(NSLayoutCons ...

  3. objective-c自学总结(二)---init/set/get方法

    一:类的声明和实现: 声明:(放在“类名+.h”文件中). 类的声明主要有两部分组成:实例变量和方法. 例 #import <Foundation/Foundation.h> @inter ...

  4. ionic:Build mobile apps faster with the web technologies you know and love

    http://ionicframework.com/getting-started/ 5 Ionic Framework App Development Tips and Tricks http:// ...

  5. Convert Sorted Array to Binary Search Tree

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

  6. jQuery图片无缝轮播插件;

    图片轮播这种效果在web开发中看常见,网上的插件也有很多,最近在整理项目的过程中,把之前的图片轮播效果整合了一下,整理成一个可调用的插件以做记录,也方便更多前端爱好者来学习使用:图片的轮播原理很简单, ...

  7. HTML统一资源定位器

    w3c 更好的解释 在OSGi in action中安装bundle时要加文本传输协议,要不然shell判断不出来

  8. 转载:Comet:基于 HTTP 长连接的“服务器推”技术

    转自:http://www.ibm.com/developerworks/cn/web/wa-lo-comet/ 很多应用譬如监控.即时通信.即时报价系统都需要将后台发生的变化实时传送到客户端而无须客 ...

  9. 使用第三方工具覆写Object中方法

    我们在实际开发中,经常需要覆写Object中的equals,hashcode,toString方法,其实编写这些代码并不是很难,但很枯燥和乏味. 下面推荐Google的Guava jar包来覆写上面的 ...

  10. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...