题目链接:https://cn.vjudge.net/problem/POJ-1001

以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得,

现在把代码都般过来,等会把旧电脑弄一弄,暂时就不写题解了

代码

#include <cstdio>
#include <cstring>
struct BigInteger{
int dot, size;
char num[600];
BigInteger(int size=0, int dot=0):size(size),dot(dot) {
for (int i=0; i<600; i++) num[i]=0;
}
BigInteger(const char str[]):size(0),dot(0) {
for (int i=0; i<600; i++) num[i]=0;
int len=strlen(str);
for (int i=len-1; i>=0; i--)
if (str[i]=='0') len--;
else break;
for (int i=len-1; i>=0; i--){
if (str[i]=='.') dot=len-i-1;
else num[size++]=str[i]-'0';
}
} BigInteger operator * (const BigInteger &a) const{
BigInteger ans(size+a.size, dot+a.dot);
for (int i=0; i<size; i++){
for (int j=0; j<a.size; j++){
int tmp=num[i]*a.num[j], low=(tmp+ans.num[i+j])%10,
high=(tmp+ans.num[i+j])/10+ans.num[i+j+1];
ans.num[i+j]=low;
ans.num[i+j+1]=high;
}
}
while (ans.num[ans.size-1]==0) ans.size--;
return ans;
}
BigInteger operator ^ (const int n) const{
BigInteger ans("1"), tmp;
memcpy(&tmp, this, sizeof(*this));
for (int i=1; ; ){
if (n&i) ans=ans*tmp;
if ((i<<=1)<=n) tmp=tmp*tmp;
else break;
}
return ans;
}
void show(void){
if (dot>size-1){
printf(".");
for (int i=0; i<dot-size; i++) printf("0");
dot=0;
}
for (int i=size-1; i>=0; i--){
printf("%d", num[i]);
if (dot && i==dot) printf(".");
}printf("\n");
}
}; int main(void){
char inpt[600]; int n;
while (scanf("%s%d", inpt, &n)==2){
BigInteger a(inpt);
(a^n).show();
} return 0;
}
Time Memory Length Lang Submitted
None 352kB 1436 G++ 2018-01-20 15:27:27

POJ-1001 Exponentiation 高精度算法的更多相关文章

  1. POJ 1001 Exponentiation(大数运算)

    POJ 1001 Exponentiation 时限:500 ms   内存限制:10000 K 提交材料共计: 179923   接受: 43369 描述:求得数R( 0.0 < R < ...

  2. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  3. poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 138526   Accepted: 33859 ...

  4. POJ 1001 Exponentiation 无限大数的指数乘法 题解

    POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...

  5. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  6. POJ 1001 Exponentiation(JAVA,BigDecimal->String)

    题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...

  7. 1001. Exponentiation高精度运算总结

    解题思路 这道题属于高精度乘法运算,要求输入一个实数R一个指数N,求实数R的N次方,由于R有5个数位,而N又特别大,因此用C++自带的数据类型放不下. 解题思路是通过数组储存每次乘积结果和底数的每一位 ...

  8. poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 180325   Accepted: 43460 Descripti ...

  9. POJ 1001 Exponentiation

    题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...

随机推荐

  1. ECharts 在winform中使用(访问JS)

    ECharts 是百度的一个开源chart 数据统计库,采用html5 + js 编程方式. 有比较好的动态效果,功能很强大.能做出酷弦的效果. ECharts 一般用于web 开发.但winform ...

  2. MetaSploit攻击实例讲解------社会工程学set攻击(kali linux 2016.2(rolling))(详细)

    不多说,直接上干货! 首先,如果你是用的BT5,则set的配置文件是在 /pentest/exploits/set/set_config下. APACHE_SERVER=ONSELF_SIGNED_A ...

  3. Linux安装(虚拟机)

    ** 虚拟机安装CentOS系统 以下步骤会连续给出截图,大家自行校对即可. 首先打开虚拟机,出现的界面如上一篇文章截图所示. ** 配置虚拟机 步骤: 1.点击“创建新的虚拟机”     2.选择“ ...

  4. java web项目中资源国际化

    有一些网站会有语言栏选项: 选择英文,内容就显示为英文: 选择中文,内容就显示文中文. 这里就用到了国际化资源. 先看效果图: 步骤: 1.建立资源包: mess_en_US.properties ( ...

  5. 你不知道的JavaScript(二)数组

    作为一种线性数据结构,几乎每一种编程语言都支持数组类型.和c++.java这些强类型的语言相比,JavaScript数组有些不同,它可以存放任意类型的值.上节中有提到过JS中任意类型的值都可以赋值给任 ...

  6. 1、Windows服务器 VS Linux服务器

  7. Site Isolation Design Document

    This design document covers technical information about how Site Isolation is built.  For a general ...

  8. Hdu 2586 树链剖分求LCA

    Code: #include<cstdio> #include<cstring> #include<vector> #include<algorithm> ...

  9. Linux Kernel 5.1 RC5发布

    我们距离正式的Linux 5.1内核发布还有不到一个月的时间,而今天Linus Torvalds宣布推出预期的Linux Kernel 5.1 RC5版本.Linus Torvalds专门评论了Lin ...

  10. mac pro配置php开发环境

    mac pro自带php和apache,所以我们只要配置下就好了 // 启动Apache服务 sudo apachectl start // 重启Apache服务 sudo apachectl res ...