POJ 1001 Exponentiation 模拟小数幂
模拟小数幂
小数点位 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 模拟小数幂的更多相关文章
- POJ 1001 Exponentiation(大数运算)
POJ 1001 Exponentiation 时限:500 ms 内存限制:10000 K 提交材料共计: 179923 接受: 43369 描述:求得数R( 0.0 < R < ...
- [POJ 1001] Exponentiation C++解题报告 JAVA解题报告
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 126980 Accepted: 30 ...
- POJ 1001 Exponentiation
题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...
- [POJ] #1001# Exponentiation : 大数乘法
一. 题目 Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 156373 Accepted: ...
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...
- poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 138526 Accepted: 33859 ...
- POJ 1001 Exponentiation(JAVA,BigDecimal->String)
题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...
- 【POJ 1001】Exponentiation (高精度乘法+快速幂)
BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...
- Poj 1001 / OpenJudge 2951 Exponentiation
1.链接地址: http://poj.org/problem?id=1001 http://bailian.openjudge.cn/practice/2951 2.题目: Exponentiatio ...
随机推荐
- poj1988 简单并查集
B - 叠叠乐 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:30000KB 64bit ...
- n!(n的阶乘)
我们在这里介绍一些关于n!的性质. 在计数问题中,经常需要用到n!.有必要了解n!在mod p下的一些性质.下面我们假设p是素数,n!=ape(a无法被p整除),并试图求解e和a mod p(把这个东 ...
- 一个小玩具:NDK编译SDL的例子
NDK编译SDL 准备: 硬件 一台电脑,实验在Lenovo T430上 一个Android设备,实验在 三星S3/A7 编译环境: Ubuntu 14.04 (ant\java等命令必须支持) 工具 ...
- 《APUE》读书笔记第十二章-线程控制
本章中,主要是介绍控制线程行为方面的内容,同时介绍了在同一进程中的多个线程之间如何保持数据的私有性以及基于进程的系统调用如何与线程进行交互. 一.线程属性 我们在创建线程的时候可以通过修改pthrea ...
- nodejs javascript微信开发
1.当从第三方软件需要分享到微信的时候 需要给授权处理才能获得微信信息 比如 nickname 等昵称图像等 从第三方登陆跳转到微信分享页需要 shareurl = http://open.weixi ...
- 如何看懂XDEBUG+WEBGRIND?(转)
看到一个很有用的东东,收藏.. http://blog.csdn.net/yukon12345/article/details/11408617 ~~~~~~~~~~ 使用: ...
- 树莓派 (Raspberry Pi) 是什么?普通人怎么玩?(私有云NAS也会有;上传到百度盘的功能nas也有)
作者:王震宇链接:https://www.zhihu.com/question/20859055/answer/54734499来源:知乎著作权归作者所有,转载请联系作者获得授权. 我两年前买的(约2 ...
- 关于bat文件语法
@echo offecho 当前盘符:%~d0echo 当前盘符和路径:%~dp0echo 当前批处理全路径:%~f0echo 当前盘符和路径的短文件名格式:%~sdp0echo 当前CMD默认目录: ...
- back_inserter的用法
1,代码如下: #include<iostream> #include<list> #include<algorithm> #include<iterator ...
- [置顶] API相关工作过往的总结之Sandcastle简要使用介绍
Sandcastle介绍 在微软推出Sandcastle之前,人们倾向于选择开源的NDoc(.NET代码文档生成器).NDo可以将 C#.NET 编译生成的程序集和对应的 /doc XML文档,自动转 ...