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. java 21 - 10 文本文件和集合之间互相存储数据

    有时候,我们会遇到单独写入数据到文本文件的情况.比如: 需求:把ArrayList集合中的字符串数据存储到文本文件 分析: A:ArrayList集合中存储的是String类 B:要存储的文件是文本文 ...

  2. INADDR_ANY的确切含义

    INADDR_ANY就是inet_addr("0.0.0.0") 首先,需要明确的是当服务器的监听地址是INADDR_ANY时设置的是服务器的IP地址. 其次,当服务器的监听地址是 ...

  3. php基础08:改变数据类型

    <?php //1.获取数据类型 $num = 55; echo gettype($num); //integer //2.设置数据类型 settype($num, "string&q ...

  4. VS2010报错无法编译:LINK : fatal error LNK1123: failure during conversion to COFF: file invalid

    win7 64位 专业版 + vs2010 从vc6.0下转过来的一个项目,突然遇到这个问题. 解决方案: 用C:\Windows\winsxs\x86_netfx-cvtres_for_vc_and ...

  5. [CareerCup] 8.9 An In-memory File System 内存文件系统

    8.9 Explain the data structures and algorithms that you would use to design an in-memory file system ...

  6. springmvc学习笔记(一)之简介

    一.简介 SpringMVC 是一个MVC框架,是基于Model-View-Controller模式实现的.类似于Struts2等mvc框架使数据-业务-展现很好的隔离开. 每当用户在web浏览器点击 ...

  7. 实验箱FPGA部分测试报告及A8与FPGA链接测试报告

    其实,我一开始还以为实验箱不会有什么问题只是让我们多学习东西才做这个测试的,结果发现还真的有不少问题. 1.实验准备部分 安装驱动时,win10系统无法正确安装usb-blaster Windows ...

  8. VmWare Workstation 10 安装 Ubuntu 14.04 问题解决

    Ubuntu安装过程很顺利,安装完成后还是有小问题存在   问题1:无法联网,PING可以通,网址无法解析 原因:默认DNS设置不正确 解决:设置DNS地址为8.8.8.8,问题解决   问题2:vm ...

  9. HoloLens开发手记 - Known issues 已知问题

    本文主要提及一份问题清单,这些问题都可能对我们开发HoloLens应用造成困扰. Visual Studio 在使用VS 2015 Update 1连接HoloLens时,可能会有些小问题.但是这些小 ...

  10. js的设计模式

    <Practical Common Lisp>的作者 Peter Seibel 曾说,如果你需要一种模式,那一定是哪里出了问题.他所说的问题是指因为语言的天生缺陷,不得不去寻求和总结一种通 ...