Problem F: Exponentiation大数求幂
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
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 \le 25$.
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the 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
思路:注意当输入1.10000时我是先变成1.1处理
#include<stdio.h>
#include<iostream>
using namespace std;
#include<string.h>
void chengfa(char a[],char b[])
{
int sum[];
int lena=strlen(a)-;
int lenb=strlen(b)-;
int t1=lena;
int t;
memset(sum ,,sizeof(sum));
for(int i=lena;i>=;i--)
for(int j=lenb,t=-(t1-i);j>=;j--)
sum[t--]+=(a[i]-'')*(b[j]-'');
for(int k=;k>=;k--)
{
sum[k-]+=sum[k]/;
sum[k]=sum[k]%;
}
int start=;
while(start<=&&!sum[start])
start++;
memset(a,,sizeof(a));
int t2=;
for(int k=start;k<=;k++)
a[t2++]=sum[k]+'';
a[t2]='\0'; }
int main()
{
char a[],b[];
char a1[],a2[];
int n;
memset(b,,sizeof(b));
while(cin>>a>>n)
{
int k6;
int len6=strlen(a);
for(k6=len6-;k6>=;k6--)
if(a[k6]!='')
{
a[k6+]='\0';
break;
}
int len1=strlen(a);
int k;
for(int i=;i<len1;i++)
if(a[i]=='.')
{ k=(len1-)-i;
int j;
for(j=i;j<len1;j++)
a[j]=a[j+];
a[j]='\0';
len1--;
break; }
int num=k*n;
strcpy(b,a);
n=n-;
while(n--)
chengfa(a,b);
int len2=strlen(a);
int count1=;
int k1,k2,k3,k4;
int lena=strlen(a)-count1;
if(num<lena) 没有前导0,即第一个是数字是大于0
{
for(k1=;k1<lena-num;k1++)
cout<<a[k1];
cout<<'.';
for(k2=k1;k2<lena;k2++)
cout<<a[k2];
cout<<endl;
}
else //有前导0
{ printf(".");
for(k3=num-lena;k3>;k3--)
printf("");
cout<<a;
cout<<endl;
}
}
return ;
}
Problem F: Exponentiation大数求幂的更多相关文章
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
- poj1001 Exponentiation 大数的幂
Description Problems involving the computation of exact values of very large magnitude and precision ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 快速求幂(Quick Exponentiation)
接触ACM没几天,向各路大神求教,听说ACM主要是研究算法,所以便开始了苦逼的算法学习之路.话不多说,RT所示,学习快速求幂. 在头文件<math.h>或是<cmath>中,d ...
- 如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 求幂大法,矩阵快速幂,快速幂模板题--hdu4549
hdu-4549 求幂大法.矩阵快速幂.快速幂 题目 M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 ...
- 大数求模 sicily 1020
Search
- C# 高精度求幂 poj1001
高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...
- 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模
题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...
随机推荐
- .NET,你忘记了么?(八)—— 从dynamic到特性误用 [转]
1. 摘要 每个程序员都想写出漂亮的代码,但是什么是漂亮,这个我想每个人都有着自己的看法.那么我就说几种典型的想法: A. 写出别人看不懂的代码,让别人觉得很高深. B. 写出简短的代码 C. 用最新 ...
- Unity大中华区主办 第二届Unity 游戏及应用大赛 实力派精品手游盘点
Unity是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏.建筑可视化.实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎.包含如今时 ...
- MVC5 Controller简要创建过程(1):ControllerFactory的创建
即将离职,闲来无事回顾下MVC的源码,到了Controller创建这里,由于流程有点复杂,鉴于自己记性不太好,索性就记录一下吧,方便日后参照. 首先看MvcHandler: public class ...
- EF5 通用数据层 增删改查操作,泛型类(转)
using System; using System.Collections.Generic; using System.Data.Entity.Infrastructure; using Syste ...
- JavaScript 中的面向对象的初步认识
我在学习JS的面向对象编程的时候,总是有两个奇怪的问题. 第一个就是:面向对象在JS中很少用到... 可能是目前自己做的项目还是比较简单,前端方面的任务我几乎都是用面向过程的方式写的,所以就导致,我啃 ...
- C# 懒人常用异步方法
Winform this.Invoke(new Action(() => { })); Wpf this.Dispatcher.Invoke(DispatcherPriority.Normal, ...
- ftp上来显示的时间和系统时间不一致
ftp上来显示的时间和系统时间不一致,是因为默认情况下,vsftpd 是用GMT做为他的时间的,所以和系统的时间可能会不一致 修改也非常简单: vi /etc/vsftpd/vsftpd.conf 在 ...
- BOOST_PP_INC_I(x)实现
这个比较有意思,# define BOOST_PP_INC_I(x) BOOST_PP_INC_ ## x 连接在一起以后,然后定义为x+1 实现了inc功能,不过最多也就到255 # /* Copy ...
- C#获得命令提示符输出
原文:http://blog.csdn.net/abrahu/article/details/6611504 C#获得命令提示符输出 分类: c#应用程序2011-07-16 23:34 600人阅读 ...
- 再看static数据成员
当将类的某个数据成员声明为static时,该静态数据成员只能被定义一次,而且要被同类的所有对象共享.各个对象都拥有类中每一个普通数据成员的副本,但静态数据成员只有一个实例存在,与定义了多少类对象无关. ...