51Nod 1873 初中的算术
大神的字符串快速幂
#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 初中的算术的更多相关文章
- 51nod 1873 初中的算术【Java BigDecimal/高精度小数】
1873 初中的算术 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ...
- 1873 初中的算术(java大数)
1873 初中的算术 1 秒 131,072 KB 10 分 2 级题 Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ⋯× a) ...
- 51nod 1873 高精度计算
JAVA BigDecimal import java.util.*; import java.math.*; public class Main { public static void main( ...
- 51nod 1189 算术基本定理/组合数学
www.51nod.com/onlineJudge/questionCode.html#!problemId=1189 1189 阶乘分数 题目来源: Spoj 基准时间限制:1 秒 空间限制:131 ...
- 51Nod 1005 有负数的高精度加法
51Nod是个好地方啊 题意 51Nod基础题第二题,高精度加法,可能有负数. 解题 如果按照一般的高精度,我们发现要分情况讨论,还要写高精度加法和减法,代码实现有点烦.而初中数学里说,省略加号的和. ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
随机推荐
- @P0或@P1附近有语法错误
分析:@P0指的是第一个参数附近有错误;为'@P1'指的是第二个参数附近错误语法有错误.
- java使用ftp局域网内多线程上传图片过慢
多线程ftp上传文件时候,图片上传很慢,调试和查询资料发现主要在:storeFile方法 解决方案如下: FTPClient fc设置setBufferSize 可以根据内存大小适当设置大点的缓冲区: ...
- 建立FTP服务器(FTP服务器名要与创建的用户名一致)
1新建用户 2. 3.建立FTP
- [NOIP2011提高组day2]-1-计算系数
1.计算系数 (factor.cpp/c/pas) [问题描述] k n m给定一个多项式(ax+by)^k ,请求出多项式展开后(x^n)*(y^m)项的系数. [输入] 输入文件名为 factor ...
- Android 6.0 如何默认打开user版本的root权限【转】
本文转载自:http://blog.csdn.net/wangjicong_215/article/details/77601638 1.system/core/adb/Android.mkdiff ...
- Gradients渐变属性
一个很不错的网站http://www.w3schools.com/css/css3_gradients.asp http://www.w3cplus.com/css3/new-css3-linear- ...
- HDU5950 Recursive sequence —— 矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-5950 Recursive sequence Time Limit: 2000/1000 MS (Java/Others) ...
- Technocup 2017 - Elimination Round 2 C. Road to Cinema —— 二分
题目链接:http://codeforces.com/problemset/problem/729/C C. Road to Cinema time limit per test 1 second m ...
- ffplay 一些好玩的filter
添加字幕:ffplay -vf drawtext="fontfile=arial.ttf: text='Test Text': x=100: y=300: \ fontsize=48: fo ...
- 用css截取字符 css排版隐藏溢出文本
方法一: <div style="width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;& ...