题目链接: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. Ubuntu下gcc安装

    在Ubuntu下安装GCC和其他一些Linux系统有点不一样. 方法一: 该方法超简单:sudo apt-get  build-depgcc 就上面这条命令就可以搞定 方法二:sudo apt-get ...

  2. AOP为Aspect Oriented Programming的缩写,意为:面向切面编程

    在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的 ...

  3. 一个简单的MyBatis项目(应用)

    ### 1. MYBATIS简介  MYBATIS是持久层框架,大大的简化了持久层开发.  当使用MYBATIS框架时,开发人员不必再编写繁琐的JDBC代码,只需要定义好每个功能对应的抽象方法与需要执 ...

  4. python 之 MRO 异常

    今天突然遇到这个异常,先贴两个地址,待有时间写博客 https://www.jianshu.com/p/fea6e0a0cc14 https://makina-corpus.com/blog/meti ...

  5. k8s使用cephfs

    以下为ceph集群操作内容 cephfs 将cephfs挂载到一台服务器 /mnt/cephf . 创建目录 mkdir -p /mnt/cephf/k8s/staff-nginx/{conf,dat ...

  6. react-native 运行提示红屏 error: bundling failed: ambiguous resolution: module `/User/xxx/Project/ico/index.js` tries to require `react-native`, but there are several files providing this module. You can de

    运行 react-native start 报错 执行这2个进行清除缓存问题 yarn start -- --reset-cache  npm start -- --reset-cache  

  7. vue-quill-editor-upload : 实现vue-quill-editor上传图片到服务器

    vue-quill-editor-upload git: https://github.com/NextBoy/vu... A plug-in for uploading images to your ...

  8. redis为什么选择单线程工作模型

    1.先说一下为什么出现进程,线程 进程:在计算机发明之初就发现,在输入数据时(I/O速度慢),CPU是空闲的,这样就浪费了CPU资源,为了充分利用CPU资源,发明了进程,在输入程序A的数据时,程序B在 ...

  9. Mysql 日期型,索引查询的问题

    问题: 表中,有一个日期字段WorkDate(Date YYYY-MM-DD格式),现在我把它建成了索引,在检索条件时,WorkDate='YYYY-MM-DD' 时,用EXPLAIN分析,能看到使用 ...

  10. 基于json数据格式实现的简单数据库——jsonDB

    已在github上建立项目:https://github.com/ThinkerCodeChina/jsonDB /** +-------------------------------------- ...