【poj1001】 Exponentiation
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的更多相关文章
- 【PKU1001】Exponentiation(高精度乘法)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 145642 Accepted: 35529 ...
- 【poj】1001
[题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...
- 【POJ2406】 Power Strings (KMP)
Power Strings Description Given two strings a and b we define a*b to be their concatenation. For exa ...
- 【POJ2406】【KMP】Power Strings
Description Given two strings a and b we define a*b to be their concatenation. For example, if a = & ...
- poj2406 Power Strings 【KMP】
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- 【343】MathJax、LaTex、Mathml 数学公式
参考:cnblog中添加数学公式支持 分类参考: 1. 基本功能 MathJax 我的LaTeX入门 MathJax basic tutorial and quick reference 分段函数:矩 ...
- 【转】DotNet加密方式解析--非对称加密
[转]DotNet加密方式解析--非对称加密 新年新气象,也希望新年可以挣大钱.不管今年年底会不会跟去年一样,满怀抱负却又壮志未酬.(不过没事,我已为各位卜上一卦,卦象显示各位都能挣钱...).已经上 ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 【原】谈谈对Objective-C中代理模式的误解
[原]谈谈对Objective-C中代理模式的误解 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这篇文章主要是对代理模式和委托模式进行了对比,个人认为Objective ...
随机推荐
- java 14 -6 BigInteger和BigDecimal
BigInteger:可以让超过Integer范围内的数据进行运算 构造方法: BigInteger(String val) import java.math.BigInteger; public c ...
- SQL 第一范式、第二范式、第三范式、BCNF
作者 : Dolphin 原文地址: http://blog.csdn.net/qingdujun/article/details/27365979 一.第一范式 1NF 要求:每一个分量必须是不可分 ...
- git review报错一例
在线上修改代码,最后使用git review提交代码审核的时候出现报错如下:[wangshibo@115~]$ vim testfile #修改代码[wangshibo@115~] ...
- 第二章 下山遇虎(@helper)
@helper方法定义 使用@helper关键字可以定义一个方法,这样就可以在页面中调 用这个方法了,和C#中的方法一样.在页面中定义的方法可以访问ViewBag,HttpContext等等页面的属性 ...
- Android Studio Jar、so、library项目依赖
Eclipse跟AS的不同 从Eclipse到AS不要带着在Eclipse中的主观色彩去在AS中使用,从项目的构成到构建是不同的,下面列举在Eclipse和AS中的一些概念的区别: WorkSpace ...
- 那些OVER的封装
什么over什么,如pppoe, ppp的封装都在over对象之后,入下图: PPPOE Ipsec
- DEDECMS中直接通过数据库插入文章
突然想用爬虫爬来的数据对接DEDECMS,所以研究了一下怎么直接在DEDECMS中直接插入一片文章 (但其实我并没有这样用.因为我直接用前台做的网页,用ajax请求的json数据,其他的都简单,就是没 ...
- 将Html文档整理为规范XML文档
有多种方式可以在.NET 平台进行HTML文件解析.数据提取,其中最简单.稳妥的办法是先使用工具将Html文档整理成XML文档,再通过XML Dom模型或XPath灵活地进行数据处理.SGML便是一个 ...
- OpenShift
一步一脚印 停停走走,回头看看 博客园 首页 新随笔 联系 订阅 管理 随笔 - 24 文章 - 8 评论 - 2 调戏OpenShift:一个免费能干的云平台 一.前因后果 以前为了搞微信的 ...
- 系分过了,mark一下,就从这里开始吧
算是重新归回吧,发现写博客还是这里人气比较旺,开源中国不行,动弹人气还可以,不过都没啥节操, 这么多年没来了,发现竟然还排名1150,不容易,继续加油.有种回娘家的赶脚