POJ1001(C++处理大数)
| Time Limit: 500MS | Memory Limit: 10000K | |
| Total Submissions: 158025 | Accepted: 38470 |
Description
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input
Output
Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=;
struct BigInt{
int e[MAXN],len,pp;
BigInt()
{
memset(e,,sizeof(e));
len=;
pp=;
}
void set(const char s[])
{
int l=strlen(s);
for(int i=;i<l;i++)
{
if(s[i]=='.')
{
pp=l-i-;
continue;
}
e[len++]=s[i]-'';
}
for(int i=;i<len/;i++)
{
int t=e[i];
e[i]=e[len-i-];
e[len-i-]=t;
}
while(len>&&e[len-]==) len--;
}
BigInt operator*(const BigInt &b)
{
BigInt ret;
for(int i=;i<len;i++)
{
int up=;
for(int j=;j<b.len;j++)
{
int z=e[i]*b.e[j]+up+ret.e[i+j];
ret.e[i+j]=z%;
up=z/;
}
if(up!=)
{
ret.e[i+b.len]=up;
}
}
ret.len=len+b.len;
ret.pp=pp+b.pp;
while(ret.len>&&ret.e[ret.len-]==) ret.len--;
return ret;
}
void print()
{
int limit=;
while(e[limit]==&&limit<pp) limit++;//去后导0
if(pp>=len)
{
printf(".");
for(int i=pp;i>len;i--)
{
printf("");
}
for(int i=len-;i>=limit;i--)
{
printf("%d",e[i]);
}
printf("\n");
}
else
{
for(int i=len-;i>=pp;i--)
{
printf("%d",e[i]);
}
if(limit<pp)
{
printf(".");
for(int i=pp-;i>=limit;i--)
{
printf("%d",e[i]);
}
}
printf("\n");
}
}
};
char buf[];
int n;
int main()
{
while(scanf("%s%d",buf,&n)!=EOF)
{
BigInt t;
t.set(buf);
BigInt res;
res.set("1.0");
for(int i=;i<n;i++)
{
res=res*t;
}
res.print();
}
return ;
}
POJ1001(C++处理大数)的更多相关文章
- poj1001 Exponentiation【java大数】
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 183034 Accepted: 44062 ...
- poj1001 Exponentiation 大数的幂
Description Problems involving the computation of exact values of very large magnitude and precision ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- c语言经典算法——查找一个整数数组中第二大数
题目: 实现一个函数,查找一个整数数组中第二大数. 算法思想: 设置两个变量max1和max2,用来保存最大数和第二大数,然后将数组剩余的数依次与这两个数比较,如果这个数a比max1大,则先将max1 ...
- 杨氏矩阵:查找x是否在矩阵中,第K大数
参考:http://xudacheng06.blog.163.com/blog/static/4894143320127891610158/ 杨氏矩阵(Young Tableau)是一个很奇妙的数据结 ...
- 蓝桥杯算法提高 P1001(大数乘法)
算法提高 P1001 时间限制:1.0s 内存限制:256.0MB 当两个比较大的整数相乘时,可能会出现数据溢出的情形.为避免溢出,可以采用字符串的方法来实现两个大数之间的乘法. 具体 ...
- 51nod 1005 大数加法
#include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...
- PHP大数(浮点数)取余
一般我们进行取余运算第一个想到的就是用百分号%,但当除数是个很大的数值,超出了int范围时,这样取余就不准确了. php大数(浮点数)取余函数 /** * php大数取余 * * @param int ...
随机推荐
- iOS基础动画的KeyPath取值
一 .基础动画 1.基础动画的属性详解 注:Core Animation的动画执行过程都是在后台操作的,不会阻塞主线程. 属性 解读 Autoreverses 设定这个属性为 YES 时,在它到达目的 ...
- 基本jquery
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- DevOps means no Ops!
DevOps means no Ops! 只单纯地搞网络的话或许你可以搞得非常好,并且获得不错的薪资,不过,5年后~10年后~,那时候随便一个人经过简单的学习就能通过Web界面或者专用的工具就能搞定一 ...
- Python常用转换函数
字符串转换为整数 int() 如int('2'). 字符串转换为浮点数 float() 如float('12.34') ASCII码转换为字符 chr() 如chr(97) 字符转换为ASCII码 o ...
- linux下无线鼠标驱动执行流程
操作系统: debian 7.4(linux 3.2.54) 硬件: 一个无线鼠标.一个有线鼠标.usb集线器. 从淘宝上花了15块钱买了个无线鼠标,很好奇它的驱动程序是如何执行的. 首先将usb集线 ...
- HDU 找到唯一的冠军
产生冠军 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 《机器学习实战》学习笔记第八章 —— 线性回归、L1、L2范数正则项
相关笔记: 吴恩达机器学习笔记(一) —— 线性回归 吴恩达机器学习笔记(三) —— Regularization正则化 ( 问题遗留: 小可只知道引入正则项能降低参数的取值,但为什么能保证 Σθ2 ...
- 字典树 HDU 1251 统计难题
;} 之前写的#include<iostream> #include<algorithm> #include<stdio.h> using namespace st ...
- vim配置与使用
Vim 是一个上古神器,本篇文章主要持续总结使用 Vim 的过程中不得不了解的一些指令和注意事项,以及持续分享一个前端工作者不得不安装的一些插件,而关于 Vim 的简介,主题的选择,以及为何使用 vi ...
- CreateProcess 执行CMD命令,并重定向输出
1. 参考网址:http://www.cnblogs.com/cnarg/archive/2011/02/20/1959292.html function TfrmMain.ExecDosCmd :b ...