hdu1715
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的更多相关文章
- hdu1715(Java)大数相加
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...
- hdu1715 大菲波数
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1715 Problem ...
- 大菲波数(Fibonacci)java大数(hdu1715)
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
- 杭电 OJ 提交代码需要注意的问题
杭电acm 提交代码需要注意的问题 1. 用 Java 的时候类名请用 Main 2. Java 提交出现 PE 的可能原因有 1) 最基本的错误是空格问题,比如注意每行的末尾是否输出空格 2) 用 ...
- 大数问题,通常用JAVA
e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...
- Java大数练习第二弹
hdu1250 水题 题目链接:pid=1250">http://acm.hdu.edu.cn/showproblem.php?pid=1250 import java.util.*; ...
随机推荐
- 管理员必备的20个Linux系统监控工具
需要监控Linux服务器系统性能吗?尝试下面这些系统内置或附件的工具吧.大多数Linux发行版本都装备了大量的监控工具.这些工具提供了能用作取得相关信息和系统活动的量度指标.你能使用这些工具发现造成性 ...
- AMD 和 CMD as lazy as possible
http://blog.chinaunix.net/uid-26672038-id-4112229.html AMD 与 CMD 区别到底在哪里? 看了以上 AMD,requireJS 与 ...
- python小算法(一)
1.长度为m的字符串a,长度为n的字符串b,(m>n) 判断b中的字母是否全在a中? O(n)最小. class Num(object): def getNum(self, m): numLis ...
- [转]Ubuntu 12.04开机自动挂载Windows分区
[转]Ubuntu 12.04开机自动挂载Windows分区 http://www.cnblogs.com/A-Song/archive/2013/02/27/2935255.html 系统版本:Ub ...
- Qt使用QStackedWidget实现堆栈窗口
Qt使用QStackedWidget实现堆栈窗口 分类: QT2012-07-25 21:59 6997人阅读 评论(0) 收藏 举报 qtlistsignal 堆栈窗口可以根据选择项的不同显示不同的 ...
- com.ibatis.sqlmap.client.SqlMapException: There is already a statement named search in this SqlMap.
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeExcep ...
- Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...
- EF之外键Include() left join
项目中用EF实现外键查询出的数据, 查询数量正确, 但实现返回数据集数量不对 //DbContext.cs HasRequired(s => s.ClassRoom) .WithMany() . ...
- Android -- ViewRoot,关于子线程刷新UI
Android在4.0之后执行线程更新UI操作会报异常:CalledFromWrongThreadException:Only the original thread that created a v ...
- CRT团队组员博客地址统计
CRT团队GitHub地址:https://github.com/CoffeeRobotTeam/Coffee-Robot-System 洪超 http://www.cnblogs.com/chaoh ...