模拟小数幂

小数点位 pos

非零末位 e

长度 len

只有三种情况 

  pos > len

  pos < e

  e < pos < len

 #include <iostream>
#include <cstring>
using namespace std;
int a[], b[], c[];
void Cal()
{
memset(c, , sizeof(c));
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
c[i+j] += a[i] * b[j];
for (int i = ; i < ; i++){
c[i+] += c[i]/;
c[i] %= ;
}
memset(a, , sizeof(a));
for (int i = ; i <= ; i++)
a[i] = c[i];
}
char s[];
int pos, n, len;
int main()
{
while(cin>>s>>n)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
int t = ;
for (int i = ; i >= ; i--)
{
if(s[i]=='.') pos = i;
else b[t++] = s[i] - '';
}
a[] = ;
for(int i = ; i <= n; i++) Cal();
len = ;
while(!c[len] && len>=) len--;
int e = ;//末尾
while(!c[e] && e<= len) e++;
pos = - pos; pos *= n;//小数点
if(pos > len)
{
cout<<".";
for (int i = pos-; i >= e; i--) cout<<c[i];
cout<<endl;
}
else if(pos <= e)//整数
{
for (int i = len; i >= pos; i--) cout<<c[i];
cout<<endl;
}
else//普通
{
for (int i = len; i >= pos; i--) cout<<c[i];
cout<<".";
for (int i = pos-; i >= e; i--) cout<<c[i];
cout<<endl;
}
}
}

POJ 1001 Exponentiation 模拟小数幂的更多相关文章

  1. POJ 1001 Exponentiation(大数运算)

    POJ 1001 Exponentiation 时限:500 ms   内存限制:10000 K 提交材料共计: 179923   接受: 43369 描述:求得数R( 0.0 < R < ...

  2. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  3. POJ 1001 Exponentiation

    题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...

  4. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  5. POJ 1001 Exponentiation 无限大数的指数乘法 题解

    POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...

  6. poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 138526   Accepted: 33859 ...

  7. POJ 1001 Exponentiation(JAVA,BigDecimal->String)

    题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...

  8. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

    BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...

  9. Poj 1001 / OpenJudge 2951 Exponentiation

    1.链接地址: http://poj.org/problem?id=1001 http://bailian.openjudge.cn/practice/2951 2.题目: Exponentiatio ...

随机推荐

  1. net.sf.json.JSONException: There is a cycle in the hierarchy!

    因为项目中使用了AJAX技术,jar包为:json-lib.jar,在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题: 如hibernate延迟加载错误,这都是些老问题了,一看就知 ...

  2. HIVE快速入门

    (一)简单入门 1.创建一个表 create table if not exists ljh_emp( name string, salary float, gender string) commen ...

  3. 使用PHP-Barcode轻松生成条形码(一)

    最近由于工作需要,研究了一下PHP如何生成条形码.虽然二维码时下比较流行,但是条形码依然应用广泛,不可替代.园子里有很多讲利用PHP生成条形码的文章,基本上都是围绕Barcode Bakery的,它虽 ...

  4. 智能的PHP缩图类

    *作者:落梦天蝎(beluckly)*完成时间:2006-12-18*类名:CreatMiniature*功能:生成多种类型的缩略图*基本参数:$srcFile,$echoType*方法用到的参数:$ ...

  5. discuz 使模板中的函数不解析 正常使用

    <!--{if $_GET['zcdw']=="baxi"}--><!--{eval $duiwuxinxi = "巴西队";}-->& ...

  6. 【Beta】Phylab2.0: Postmortem

    设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 主要解决同学们写物理实验报告时,处理数据的困难--巨大的计算量和不规范的物理报告数据处理格式.典型 ...

  7. 提交svn报错说 有 unversioned 的文件

    这个说明   有未add的图片等东西,需要先add进去再提交

  8. UltraEdit-32 恢复到初始默认配置

    不小心把UltraEdit-32搞乱了,字体不管怎么设置,都回不去了..然后那些菜单也被弄得乱七糟八的....于是就想把这些设置都搞成默认的.重装UltraEdit-32.清理注册表.结果发现都没有用 ...

  9. logstash nginx 报ArgumentError: comparison of String with 5 failed

    80.82.78.38 [23/Sep/2016:05:36:18 +0800] "GET http://www.baidu.com/cache/global/img/gs.gif HTTP ...

  10. 【转】ubuntu12.04完美安装QQ2012、QQMusic、Foxmail等--wine

    原文网址:http://blog.csdn.net/hanmengaidudu/article/details/17616921 其实在这之前,试过无数次的wine模拟,没有一次成功的,也不能说是不成 ...