模拟小数幂

小数点位 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. Javascript获取某个月的天数-简单方法 .(转别人的)

    Javascript里面的new  Date("xxxx/xx/xx")这个日期的构造方法有一个妙处,当你传入的是"xxxx/xx/0"(0号)的话,得到的日期 ...

  2. html5 画布上的rotate使用

    作为刚进公司的毕业生,第一个项目便是开发html5游戏,于是网上搜寻各种有关html5的资料,把w3School中有关html5的教程通通过了一遍,发现里面的教程非常适合刚接触html5的人,作为菜鸟 ...

  3. 解决redis-cli连接时出现Could not connect to Redis at 127.0.0.1:6379: Connection refused

    执行redis 配置文件 redis-server  /etc/redis/redis.conf

  4. C语言初学 比较五个整数并输出最大值和最小值1

    #include<stdio.h> #include<math.h> int max(int x,int y) { if(x>y) return x; else retu ...

  5. 使用接口的方式调用远程服务 ------ 利用动态调用服务,实现.net下类似Dubbo的玩法。

    分布式微服务现在成为了很多公司架构首先项,据我了解,很多java公司架构都是 Maven+Dubbo+Zookeeper基础上扩展的. Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按 ...

  6. Spring AOP 原理

    AOP将应用系统分为两部分,核心业务逻辑(Core businessconcerns)及横向的通用逻辑,也就是所谓的方面Crosscutting enterprise concerns,例如,所有大中 ...

  7. 为MVC 添加下载权限

    今天碰到一个错误,极其郁闷,本地开发和本地部署测试没有问题,但是放到阿里云上,出现了权限问题. 报错:ASP.NET 无权访问所请求的资源.请考虑对 ASP.NET 请求标识授予. 参考网上很多资料, ...

  8. docker 1.10.3 里php出现 curl 56错误码问题解决

    http://www.cnblogs.com/fengwei/p/5899018.html

  9. Activity生命周期,状态保存恢复(经典)

    一.整体框架 二.main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  10. http://wiki.apache.org/tomcat/HowTo

    http://wiki.apache.org/tomcat/HowTo Contents Meta How do I add a question to this page? How do I con ...