http://poj.org/problem?id=1001 (题目链接)

题意

  求实数R的n次方,要求高精度。

Solution

  SB题Wa了一下午,直接蒯题解。

  高精度,小数点以及去前导后导零很麻烦,而且题目数据很刁钻。

  注意几个数据: 
  00.000 20 
  0

  000.10 20 
  .00000000000000000001

  .10000 25 
  .0000000000000000000000001

  1 0 
  1

  如果还要数据大话,大牛博客上有。

代码

#include<iostream>
using namespace std;
char str[10];
int n, dot;
int res[999999], a[999999], b[999999];
int len, lena, lenb; void mul()
{
int i, j;
memset(res, 0, sizeof(res));
for (i=1; i<=lena; i++)
{
for (j=1; j<=lenb; j++)
{
res[i+j-1] += a[i] * b[j];
if (res[i+j-1]>9)
{
res[i+j] += res[i+j-1] / 10;
res[i+j-1] %= 10;
}
}
}
if (res[lena+lenb-1]>9)
{
res[lena+lenb] += res[lena+lenb-1] / 10;
res[lena+lenb-1] %= 10;
}
lena = lena + lenb;
for (i=1; i<=lena; i++) a[i] = res[i];
} int main()
{
int i, j, up, down;
while (scanf("%s %d", str, &n)!=EOF)
{
dot = -1;
for (i=5, j=1; i>=0; i--)
{
if (str[i]!='.') a[j] = b[j++] = str[i] - '0';
else dot = i;
}
if (dot==-1) lena = lenb = 6;
else lena = lenb = 5;
for (i=1; i<n; i++) mul();
if (dot==-1)
{
for (i=lena; i>=1; i--) printf("%d", a[i]);
printf("\n");
}
else
{
dot = 5 - dot;
dot *= n;
for (i=1; i<=lena; i++)
{
if (a[i]!=0)
{
down = i;
break;
}
}
for (j=lena; j>=1; j--)
{
if (a[j]!=0)
{
up = j;
break;
}
}
i = up;
if (up<dot) i = dot;
j = down;
if (j>dot) j = dot + 1;
for (; i>=j; i--)
{
if (i==dot) printf(".");
printf("%d", a[i]);
}
printf("\n");
}
}
return 0;
}

  

【poj1001】 Exponentiation的更多相关文章

  1. 【PKU1001】Exponentiation(高精度乘法)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 145642   Accepted: 35529 ...

  2. 【poj】1001

    [题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...

  3. 【POJ2406】 Power Strings (KMP)

    Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...

  4. 【POJ2406】【KMP】Power Strings

    Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...

  5. poj2406 Power Strings 【KMP】

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  6. 【343】MathJax、LaTex、Mathml 数学公式

    参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...

  7. 【转】DotNet加密方式解析--非对称加密

    [转]DotNet加密方式解析--非对称加密 新年新气象,也希望新年可以挣大钱.不管今年年底会不会跟去年一样,满怀抱负却又壮志未酬.(不过没事,我已为各位卜上一卦,卦象显示各位都能挣钱...).已经上 ...

  8. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  9. 【原】谈谈对Objective-C中代理模式的误解

    [原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...

随机推荐

  1. Tomcat与内存泄露

    一.Tomcat的JVM提示内存溢出 查看%TOMCAT_HOME%\logs文件夹下,日志文件是否有内存溢出错误 二.修改Tomcat的JVM 1.错误提示:java.lang.OutOfMemor ...

  2. Windows系统安装Oracle 11g数据库

    一.下载 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html以下两网址来源此官方下载页 ...

  3. Spring 4 bak

    IOC (参考<Spring企业开发>.<Spring实战 第三版  第四版>) IoC概述 1.           控制反转 2.依赖注入   控制反转:大多数情况下,想要 ...

  4. 20SpringMvc_结果的转发可共享参数;重定向不能共享参数

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* Style Definiti ...

  5. 调用Oracle存储过程并获取out参数值

    原文: http://tech.it168.com/oldarticle/2006-04-02/200604021512359.shtml http://www.cnblogs.com/m-cnblo ...

  6. C++ Set & MultiSet

    转自http://www.cppblog.com/wanghaiguang/archive/2012/06/05/177627.html STL Set介绍集合(Set)是一种包含已排序对象的关联容器 ...

  7. DIV相关的操作总结

    由于有时候需要做网站项目,遇到CSS的问题总是需要百度或者google一下,比较麻烦,索性今天就来总结一下,这里就拿div开刀先. DIV在HTML前端页面布局中,非常重要,我们经常遇到的问题是:DI ...

  8. iOS从App跳转至系统设置菜单各功能项的编写方法讲解

    跳到系统设置里的WiFi界面 info里面设置: 在项目中的info.plist中添加 URL types 并设置一项URL Schemes为prefs,如下图 代码: 复制代码 代码如下: NSUR ...

  9. Opencv实现运动检测

    运动检测多种多样,这里的需求只是检测到有运动物体就行了,而且 要尽量减少误报的情况.另外尽量降低CPU的消耗,因为最终需要在树莓派上面运行. 看了一些中文的文章,发现无法很好地理解别人说的内容,反而是 ...

  10. 给 Xamarin.Form For Windows Phone APP 加个漂亮的 "头"

    Windows Phone 是那个1%, 我也是那个1%, 不喜勿喷.WP 向来给 android / ios 的粉们一个最直观的印象: 丑.其实"丑"这个东西会一直下去,而且是个 ...