分析:大实数乘方计算。

#include<iostream>
#include<string>
using namespace std; struct BigReal //高精度实数
{
int len; //长度
int num[10000];
int point; //小数点位置
BigReal()
{
len=1;
point=0;
memset(num,0,sizeof(num));
}
}; bool Read(BigReal& a) //读入一个大实数
{
string s;
int t,i; if(cin>>s)
{
a.len=s.size();
a.point=0;
t=0;
for(i=s.size()-1;i>=0;i--)
{
if(s[i]=='.')
{
a.len--;
a.point=t;
continue;
}
a.num[t++]=s[i]-'0';
}
return true;
}
else
return false;
} void Show(BigReal& a)
{
int i,pos; for(i=0;i<a.point && a.num[i]==0;i++) ;
pos=i;
if(a.point==a.len)
{
if(pos==a.point)
{
cout<<0<<endl; //0.0000000的情况
return ;
}
else
cout<<'.'; //0.121313114的情况
}
for(i=a.len-1;i>=0;i--)
{
cout<<a.num[i];
if(i==pos) break; //小数时后导零不输出
if(i==a.point) cout<<'.';
}
cout<<endl;
} BigReal Mul(const BigReal& a,const BigReal& b)
{
int i,j,len=0;
BigReal c; for(i=0;i<a.len;i++)
for(j=0;j<b.len;j++)
{
c.num[i+j]+=a.num[i]*b.num[j];
if(c.num[i+j]>=10)
{
c.num[i+j+1]+=c.num[i+j]/10;
c.num[i+j]%=10;
}
}
c.point=a.point+b.point;
len=a.len+b.len;
while(c.num[len-1]==0 && len>1&&len>c.point) len--; //处理长度,去掉前导零
if(c.num[len]) len++;
c.len=len;
return c;
} int main()
{
BigReal a;
int b; while(Read(a)&& scanf("%d",&b)==1)
{
BigReal ans;
ans.num[0]=1;
while(b--)
ans=Mul(ans,a);
Show(ans);
}
return 0;
}

HDU ACM 1063 Exponentiation 大实数乘方的更多相关文章

  1. Exponentiation(java 大实数)

    http://acm.hdu.edu.cn/showproblem.php?pid=1063 Exponentiation Time Limit: 2000/500 MS (Java/Others)  ...

  2. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  4. hdu acm 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 题目意思:有 资金 n 和 m 种类型的大米,对第 i 种类型的大米,价格.数量.袋数分别是: ...

  5. hdu 1063 Exponentiation

    求实数的幂,这个用C++写的话有点长,但是用Java写就非常方便了…… );            System.out.println(an);        }    }}

  6. hdu 1063 Exponentiation (高精度小数乘法)

    //大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...

  7. hdu 1063 Exponentiation 大数

    Problem Description Problems involving the computation of exact values of very large magnitude and p ...

  8. hdu Exponentiation高精度实数乘幂(用了带小数的高精度模板)

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  9. HDU 1280 前m大的数

    http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...

随机推荐

  1. WordPress下载安装简单配置实例

    1.下载https://cn.wordpress.org/ 2.复制wp-config-sample.php为wp-config.php 3.创建一个wordpress数据库 4.修改wp-confi ...

  2. 动态Script标签 解决跨域问题

     动态Script 解决跨域问题 1.动态创建scriptcreateScript : function(src){ var varScript = document.createElement(&q ...

  3. 让两个Div并排显示

    一.使用display的inline属性 <div style="width:300px; height:auto; float:left; display:inline"& ...

  4. Oracle EBS-SQL (AR-2):检查应收收款核销额

    SELECT cust.customer_number, cust.customer_name, cash.receipt_number,            gcc.segment1 || '.' ...

  5. iPhone/iTouch免99美刀真机调试

    本文经本人验证,攻略来源于网上,由于多次转载原始出处不可靠,故无法对原作者进行链接引用,抱歉. 本文仅为记录流程,以备日后查询.本文版权所无,欢迎转载和拍砖. 测试环境: XCode 4.0.2 + ...

  6. 枚举与剪枝_观察算式(比标准答案还要牛B)

    观察算式 观察以下的算式: △△△ * △△ = △△△△ 某3位数乘以2位数,结果为4位数 要求:在9个△所代表的数字中.1~9的数字恰好每一个出现1次. 暴力破解代码: package lianx ...

  7. 设计模式之PHP项目应用——单例模式设计Memcache和Redis操作类

    1 单例模式简单介绍 单例模式是一种经常使用的软件设计模式. 在它的核心结构中仅仅包括一个被称为单例类的特殊类. 通过单例模式能够保证系统中一个类仅仅有一个实例并且该实例易于外界訪问.从而方便对实例个 ...

  8. android插件化-apkplugdemo源代码阅读指南-10

    阅读本节内容前可先了解 apkplug基础教程 本教程是基于apkplug V1.6.8 版本号编写  最新开发方式以官网为准 可下载最新的apkplugdemo源代码http://git.oschi ...

  9. curl返回值写入内存的场景

    直接上代码: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <cur ...

  10. 如何在其他类中实现继承自CFormView类的对象

    今天项目开发中,我们创建了一个对话框资源,并创建了一个派生自CFormView的类(假设为CMyClassDlg)来管理它. CMyClassDlg.h #pragma once // CMyClas ...