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 ...
随机推荐
- 读书笔记_Effective_C++_条款十七:以独立语句将new产生的对象置入智能指针
int get_int(); void f(shared_ptr<int> a, int); //下面调用 f(new int(3), get_int());//如果是类而不是int就可以 ...
- Web项目中JSP页面的一种调试方法与出现的问题 -- SpringMVC架构测试
在前端开发中,尤其是MVC架构多人开发,负责前端的童鞋总是需要做静态页面,再和后台连接前无法使用变量如EL表达式等测试功能,所以本人引入了一个模板jsp数据测试专用文件,专门配置所有的变量,然后在待测 ...
- 深度克隆(对象、数组)--------百度IFE前端task2
var srcObj = { a: 1, b: { b1: ["hello", "hi"], b2: "JavaScript" }}; co ...
- javascript事件详细说明
javascript事件列表解说javascript事件列表解说事件 浏览器支持 解说一般事件 onclick IE3.N2 鼠标点击时触发此事件ondblclick IE4.N4 鼠标双击时触发此事 ...
- C语言之链表————(转载)
#include <stdio.h>#include <malloc.h>#define LEN sizeof(struct student) /*-------------- ...
- LINUX 循环fork()
#include <sys/types.h> #include <unistd.h> int main() { for(int i = 0; i < ...
- Regular expression cheat sheet
\s white-space characters \S Non-white-space characters \d digital numbers \D non-digital numbers \w ...
- ubuntu apt 命令参数(转)
apt-get是一条linux命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载软件或操作系统. apt-get update 在修改/etc/apt/sou ...
- Microsoft.Practices.Unity 给不同的对象注入不同的Logger
场景:我们做项目的时候常常会引用第三方日志框架来帮助我们记录日志,日志组件的用途主要是审计.跟踪.和调试.就说我最常用的日志组件log4net吧,这个在.NET同行当中应该算是用得非常多的一个日志组件 ...
- op+3g
https://forum.openwrt.org/viewtopic.php?id=44895 http://eko.one.pl/forum/viewtopic.php?id=10269 http ...