BUPT2017 wintertraining(15) #6A

题意

求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25)

题解

将R用字符串读进来,找到小数点的位置,然后转为整数。

用高精度乘法和快速幂计算。输出时要确定一下小数点的位置。

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int base=10;
struct Num{
int a[1000],len;
Num(){memset(a,0,sizeof a);}
void input(int b){
int i;
if(b==0)len=1;
for(i=0;b;i++){
a[i]=b%base;
b/=base;
}
len=i;
}
void output()const {
for(int i=len-1;i>=0;i--){
printf("%d",a[i]);
}
puts("");
}
Num operator *(const Num &b)const{
Num c;
for(int i=0;i<len;i++)
for(int j=0;j<b.len;j++){
c.a[i+j]+=a[i]*b.a[j];
}
c.len=len+b.len-1;
for(int i=0;i<c.len;i++){
if(c.a[i]>=base){
c.a[i+1]+=c.a[i]/base;
c.a[i]%=base;
}
}
if(c.a[c.len])c.len++;
return c;
}
};
char s[1000],ans[1000];
int d;
Num qpow(Num n,int d){
Num ans;ans.input(1);
while(d){
if(d&1)ans=ans*n;
n=n*n;
d>>=1;
}
return ans;
}
int main() {
while(cin>>s>>d){
int i,j,b=0;
for(i=0;s[i];i++){
if(s[i]=='.'){j=i;}
else b=b*10+s[i]-'0';
}
int l=(i-j-1)*d;
Num c;c.input(b);
c=qpow(c,d);
for(i=c.len-1;i>=l;i--){
printf("%d",c.a[i]);
}
for(j=0;c.a[j]==0;j++); if(i>j)printf(".");
for(i=l-1;i>=j;i--)printf("%d",c.a[i]);
puts("");
}
return 0;
}

【POJ 1001】Exponentiation (高精度乘法+快速幂)的更多相关文章

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

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

  2. 乘方快速幂 OR 乘法快速幂

    关于快速幂这个算法,已经不想多说,很早也就会了这个算法,但是原来一直靠着模板云里雾里的,最近重新学习,发现忽视了一个重要的问题,就是若取模的数大于int型,即若为__int64的时候应该怎么办,这样就 ...

  3. poj 3070 && nyoj 148 矩阵快速幂

    poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...

  4. POJ 1001 Exponentiation(大数运算)

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

  5. Qbxt 模拟赛 Day4 T2 gcd(矩阵乘法快速幂)

    /* 矩阵乘法+快速幂. 一开始迷之题意.. 这个gcd有个规律. a b b c=a*x+b(x为常数). 然后要使b+c最小的话. 那x就等于1咯. 那么问题转化为求 a b b a+b 就是斐波 ...

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

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

  7. 整数快速乘法/快速幂+矩阵快速幂+Strassen算法

    快速幂算法可以说是ACM一类竞赛中必不可少,并且也是非常基础的一类算法,鉴于我一直学的比较零散,所以今天用这个帖子总结一下 快速乘法通常有两类应用:一.整数的运算,计算(a*b) mod c  二.矩 ...

  8. 矩阵乘法快速幂 codevs 1732 Fibonacci数列 2

    1732 Fibonacci数列 2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 在“ ...

  9. POJ 3150 Cellular Automaton --矩阵快速幂及优化

    题意:给一个环,环上有n块,每块有个值,每一次操作是对每个点,他的值变为原来与他距离不超过d的位置的和,问k(10^7)次操作后每块的值. 解法:一看就要化为矩阵来做,矩阵很好建立,大白书P157页有 ...

随机推荐

  1. Python学习之赋值列表

    # the program aim to differentiate the defference of a=b or a=b[:] my_fruits=["apple",&quo ...

  2. mysql索引及优化

    索引; 2.索引入门对于任何DBMS,索引都是进行优化的最主要的因素.对于少量的数据,没有合适的索引影响不是很大,但是,当随着数据量的增加,性能会急剧下降.如果对多列进行索引(组合索引),列的顺序非常 ...

  3. Jenkins部署net core小记

    作为一个不熟悉linux命令的neter,在centos下玩Jenkins真的是一种折磨啊,但是痛并快乐着,最后还是把demo部署成功!写这篇文章是为了记录一下这次部署的流程,和心得体会. 网上很多资 ...

  4. 用WSDL4J解析types标签中的内容

    WSDL4J是一种用来解析WSDL文本的常用工具. 但网络上用WSDL4J来解析wsdl文档complexType标签中内容的问题一大堆也没有有效的解决方法.今天在我“遍历”wsdl4j的api文档和 ...

  5. #Leetcode# 1009. Complement of Base 10 Integer

    https://leetcode.com/problems/complement-of-base-10-integer/ Every non-negative integer N has a bina ...

  6. excel vba 不可查看

    打击共享工作簿 去掉[允许多用户同事编辑,同事允许工作簿合并]

  7. MyEclipse配置tomcat报错 - java.lang.UnsupportedClassVersionError: org/apache/lucene/store/Directory : Unsupported major.minor version 51.0

    1 开发Servlet程序时,MyEclipse配置好tomcat与JDK之后,启动时控制台报下列错误: 1 java.lang.UnsupportedClassVersionError: org/a ...

  8. [转帖]整理:Windows系统下的奇技淫巧大汇总

    整理:Windows系统下的奇技淫巧大汇总 https://blog.csdn.net/bat67/article/details/76381357 Win+home Crtl+home 还有 Win ...

  9. Latex常用软件

    Linux texMaker sudo apt-get install texlive-full sudo apt-get install texmaker

  10. 网络编程--使用UDP发送接收数据

    package com.zhangxueliang.udp; import java.io.IOException; import java.net.DatagramPacket; import ja ...