大神的字符串快速幂

 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; //字符串的乘法
string multi(string a, string b){
int i, j, arr[], len = a.length() + b.length();
memset(arr, , sizeof arr);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = ; i<a.length(); i++)
for (int j = ; j<b.length(); j++)
arr[i + j] += (a[i] - '')*(b[j] - '');
for (int i = ; i<len; i++){
arr[i + ] += arr[i] / ;
arr[i] %= ;
}
string ret = string(len, '');
for (int i = ; i<len; i++)
ret[i] += arr[i];
reverse(ret.begin(), ret.end());//翻转
return ret;
}
string Str_Pow(string x, int p){
string ret = "";
while (p){
if (p & ) ret = multi(ret, x);
x = multi(x, x);
p >>= ;
}
return ret;
}
int main(){
string a;
int n;
while (cin >> a >> n){
int index = a.find('.');
if (index == -) index = ;
else {
//substr() 是字符串截取函数
a = a.substr(, index) + a.substr(index + );
index = (a.length() - index)*n;
}
a = Str_Pow(a, n);
a = a.substr(, a.length() - index) + "." + a.substr(a.length() - index);
int i;
for (i = ; i<a.length(); i++)
if (a[i] != '')
break;
//substr(i) 从i到end
a = a.substr(i);
for (int i = a.length() - ; i >= ; i--){
if (a[i] == '.'){
a = a.substr(, i);
break;
}
else if (a[i] != ''){
a = a.substr(, i + );
break;
}
}
cout << a << endl;
}
return ;
}

51Nod 1873 初中的算术的更多相关文章

  1. 51nod 1873 初中的算术【Java BigDecimal/高精度小数】

    1873 初中的算术 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ...

  2. 1873 初中的算术(java大数)

    1873 初中的算术 1 秒 131,072 KB 10 分 2 级题   Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ⋯× a) ...

  3. 51nod 1873 高精度计算

    JAVA BigDecimal import java.util.*; import java.math.*; public class Main { public static void main( ...

  4. 51nod 1189 算术基本定理/组合数学

    www.51nod.com/onlineJudge/questionCode.html#!problemId=1189 1189 阶乘分数 题目来源: Spoj 基准时间限制:1 秒 空间限制:131 ...

  5. 51Nod 1005 有负数的高精度加法

    51Nod是个好地方啊 题意 51Nod基础题第二题,高精度加法,可能有负数. 解题 如果按照一般的高精度,我们发现要分情况讨论,还要写高精度加法和减法,代码实现有点烦.而初中数学里说,省略加号的和. ...

  6. 【51Nod 1244】莫比乌斯函数之和

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...

  7. 51Nod 1268 和为K的组合

    51Nod  1268  和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...

  8. 51Nod 1428 活动安排问题

    51Nod   1428  活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...

  9. 51Nod 1278 相离的圆

    51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...

随机推荐

  1. Machine Learning in Action(0) 开篇

    现在貌似In Action很流行,各种技术抽象成工程商的Action,可以避开繁琐的内部原理,这本书从实践出发,通俗易懂的解释那些常用的机器学习算法,类似跟<集体智慧编程>.这本书中文出版 ...

  2. Linux服务器Java输出文件中文乱码

    使用下面语句查看编码: String encoding = System.getProperty("file.encoding");结果输出:ANSI_X3.4-1968,从而导致 ...

  3. android RefBase、sp、wp

    首先RefBase在android的c++部分是作为一个所有类的基类,其作用跟Java中的Object类似 这个类中存在一个私有成员: weakref_impl* const mRefs;(weakr ...

  4. Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题

    题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds me ...

  5. 关于Zookeeper

    Zookeeper是分布式协调工具 应用场景 命名服务(注册中心) Dubbo注册中心 分布式配置中心(SpringCloud config)动态管理配置文件信息 消息中间件 事件通知(类似发布订阅) ...

  6. tensorflow实现图像的翻转

    from:https://blog.csdn.net/uestc_c2_403/article/details/72703097 tensorflow内部含有实现图像翻转的函数为 tf.image.f ...

  7. 配置tomcat https的步骤

    keytool -genkey -v -alias tomcat -keyalg RSA -keystore D:\tomcat.keystore -validity 36500 keytool -g ...

  8. Lsyncd搭建同步镜像-用Lsyncd实现本地和远程服务器之间实时同步

    Lysncd即Live Syncing Daemon,它是开源的数据实时同步工具(后台进程),基于inotify和rsync. lsyncd会密切监测本地服务器上的参照目录,当发现目录下有文件或目录变 ...

  9. TModJS:使用tmodjs

    ylbtech-TModJS:使用tmodjs 1.返回顶部 1. 1.安装 npm install -g tmodjs 2.配置 我的模板都放在tpl文件夹中,htmls用于存放模板页面,每一个后缀 ...

  10. 解压缩zip,tar,tar.gz,tar.bz2文件

    .tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gunz ...