poj1001(高精度)

时间:2022-12-18 16:54:48
                                                           Exponentiation
Time Limit: 500MS   Memory Limit: 10000K
Total Submissions: 132438   Accepted: 32334

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 <= 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 R^n. Leading zeros should be suppressed in the output.
Insignificant trailing zeros must not be printed. Don't print the
decimal point if the result is an integer.

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

Hint

If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
C++

while(cin>>s>>n)

{

...

}

c

while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want

/*while(scanf(%s%d",s,&n)!=EOF) //this also work */

{

...

} 这题,最强大的是后台的测试数据,以至于让很多人没有AC,这题读了之后就会发现有几个关键点,一个是数据运算怎么处理,一个是做什么处理符合一些变态的数据,大数类的模拟手算。
首先说一下第一个,我们运算时候待着小数点计算式肯定不方便的,所以必须除去小数点,把数据当做整数计算完,然后再加上小数点,对于小数点位置的判断程序中说明。
第二个,题目中说了没意义的0不能输出,比如0.1 输出.1,比如100.10 输出100.1,我们运算可能会出现很多0,这就需要我们除去前导0,后缀零,判断数据是否大于1
第三个倒是最好解决的,数据以字符接收,存入整型数组,注意存的时候最好倒着存储,这样进位好进位一些,满十进一,输出倒着输出就OK了。
 #include<stdio.h>
#include<string.h> int output[]; //第一位为1,方便计算
int m;
//num是去掉小数点后的十进制数字,比如95.23变为9523
//因为我们要乘的数是固定的,所以可以都去掉小数点计算,最后如果有小数点加上去就行了
void cal(char str[],int num)
{
int i;
for(i=;i<m;i++)
{
output[i]=output[i]*num; //因为最大的数可能为99999,99999*9不会超出int范围的,所以先乘好,然后再考虑进位
}
for(i=;i<m-;i++)
{
if(output[i]>=)
{
output[i+]+=output[i]/;
output[i]%=;
}
}
int t = output[m-];
int p=m-;
if(t>=) //把最后一个数字比如45,存储到字符数组中
{
while(t>)
{
output[p++]=t%;
t/=;
}
}
m=p;
return ;
} int main()
{
char str[];
int n;
while(scanf("%s%d",str,&n)!=EOF)
{ int sum = ,Pointsum=;
int length = strlen(str),i;
for(i = ; i<length;i++)
{
if(str[i]=='.')
{
Pointsum = (length-(i+))*n; //记录有多少位小数
}
else
{
sum = sum* + str[i]-''; //迭代增加求完整的十进制数
}
}
if(sum==)
{
printf("0\n");
continue;
}
memset(output,,sizeof(output));
output[]=;
m=;
for(i = ;i<n;i++)
cal(str,sum); int temp = ;
for(i = ; i<m;i++) //先去掉后缀零
{
if(output[i]!=)
{
temp = i; //第一位不为零的数字
break;
}
}
if(Pointsum-temp<=) //没有小数点
for(i =m-;i>=Pointsum;i--) //temp也是非零的
printf("%d",output[i]);
else //有小数点
{
if(Pointsum>m)
m=Pointsum;
for(i=m-;i>=Pointsum;i--)
printf("%d",output[i]);
printf(".");
for(;i>=temp;i--)
printf("%d",output[i]);
}
printf("\n"); }
return ;
}

poj1001(高精度)的更多相关文章

  1. 高精度POJ1001

    今天看到这道题了 poj1001 题目地址是http://bailian.openjudge.cn/practice/1001/ 英文看得懂,可是算法不明白,所以转别人的文章,留着给学生看看:乔高建( ...

  2. POJ-1001 Exponentiation 高精度算法

    题目链接:https://cn.vjudge.net/problem/POJ-1001 以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得, 现在把代码都般过来,等会把旧电脑弄一弄,暂时就不 ...

  3. C&num; 高精度求幂 poj1001

    高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...

  4. 求高精度幂(poj1001)

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  5. CSharpGL&lpar;28&rpar;得到高精度可定制字形贴图的极简方法

    CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...

  6. 递推&plus;高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)

    题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个 ...

  7. &lbrack;Template&rsqb;高精度模板

    重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...

  8. Code&lbrack;VS&rsqb; 3123 高精度练习之超大整数乘法

    FFT 做 高精度乘法 #include <bits/stdc++.h> ); struct complex { double a, b; inline complex( , ) { a ...

  9. Java 高精度数字

    BigInteger // 高精度整数 BigDecimal //高精度小数  小数位数不受限制

随机推荐

  1. Nexpose下载安装注册一条龙

    附上两个下载链接: Windows版本(64bit) : http://download2.rapid7.com/download/NeXpose-v4/NeXposeSetup-Windows64. ...

  2. Alpha版本十天冲刺——Day 8

    站立式会议 会议总结 队员 今天完成 遇到的问题 明天要做 感想 鲍亮 无 同时发送图片和其它字段信息(string)到服务器,找不到好方法实现 完成发帖接口 心累,写好了一个传送文件的接口,但是后端 ...

  3. IOS - delegate为什么不使用retain

    循环引用所有的引用计数系统,都存在循环应用的问题.例如下面的引用关系: 对象a创建并引用了对象b.对象b创建并引用了对象c.对象c创建并引用了对象b. 这时候b和c的引用计数分别是2和1.当a不再使用 ...

  4. 团队开发——冲刺1&period;c

    冲刺阶段一(第三天) 1.昨天做了什么? 在C#的Windows窗体应用程序中,设计简单的游戏界面. 2.今天准备做什么? 首先把昨天遇到的问题解决了,虽然没有找到原因,但是只要每一步修改后就立即运行 ...

  5. jquery仿天猫商城左侧导航菜单

    之前看到有博友写了一个仿天猫商城左侧导航菜单,可惜不提供免费下载,也没有代码.以前自己也写过类似的效果,只是都是一小块一小块的,现在重新拼凑.我将一步一步的实现拼凑过程,希望对你有所帮助. Demo在 ...

  6. ThinkPHP框架的网站url重写

    nginx location / { root /var/www; index index.html index.htm index.php; if (!-e $request_filename) { ...

  7. Linux 下 Redis 安装与配置

    1.Redis 的安装 在 Ubuntu 系统安装 redis 可以使用以下命令: $ sudo apt-get update $ sudo apt-get install redis-server ...

  8. Python开发——函数【装饰器、高阶函数、函数嵌套、闭包】

    装饰器 装饰器本质就是函数,为其他函数添加附加功能. 原则: 不修改被修饰函数的源代码 不修改被修饰函数的调用方法 装饰器知识储备:装饰器 = 高阶函数 + 函数嵌套 + 闭包 案例:求函数运行时间! ...

  9. Elasticsearch5&period;x批量插入数据(Java)

    先上官方示例代码:官方示例 Java代码: // 批量插入数据 public void InsertBatch() { try { // 设置集群名称 Settings settings = Sett ...

  10. Microsoft Visual Studio 2010(vs10)安装与使用

    安装1.下载软件: 云盘分享http://pan.baidu.com/s/1i4JL9GT 2.安装 打开Microsoft Visual Studio 2010目录,双击setup.exe ,运行 ...