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 相离的圆 基 ...
随机推荐
- Machine Learning in Action(2) 决策树算法
决策树也是有监督机器学习方法. 电影<无耻混蛋>里有一幕游戏,在德军小酒馆里有几个人在玩20问题游戏,游戏规则是一个设迷者在纸牌中抽出一个目标(可以是人,也可以是物),而猜谜者可以提问题, ...
- 利用AutoLayout适配滚动视图和表视图
1.新增一个contentView,设置为与滑动视图的父视图等高等宽. 2.利用代码 if(_MyTestTableView.frame.size.height != _MyTestTableView ...
- hadoop 添加,删除节点
http://www.cnblogs.com/tommyli/p/3418273.html
- ICE协议下NAT穿越的实现(STUN&TURN)
正文: 一. 首先来简单讲讲什么是NAT? 原来这是因为IPV4引起的,我们上网很可能会处在一个NAT设备(无线路由器之类)之后.NAT设备会在IP封包通过设备时修改源/目的IP地址. 对于家用路由器 ...
- codeforces C. New Year Ratings Change 解题报告
题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同 ...
- Understand JavaScript’s “this” With Clarity, and Master It
The this keyword in JavaScript confuses new and seasoned JavaScript developers alike. This article a ...
- Hihocder 1639 : 图书馆 (组合数+唯一分解 求最后一位)(妙)
给定n,(n<=10^3),然后输入n的数a[i],(a[i]<=1e10),求ans=(a1+a2+a3...an)! / (a1!*a2!*a3!...an!) 的结果的最一位数. 适 ...
- jquery的跨域请求
项目中关于ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法总算搞定了,记录一下 function TestAjax() { $.ajax({ ...
- WinThruster中文版破解方法(注册表无伤清理工具)
每次卸载完软件,都会有注册表残余垃圾,久而久之电脑会越来越慢,winThruster可以检测出系统无用注册表,并删除. 1.解压文件,安装Setup_WinThruster_2015.exe文件. 2 ...
- NOI 2012 魔幻棋盘 | 二维差分 + 二维线段树
题目:luogu 2086 二维线段树,按套路差分原矩阵,gcd( x1, x2, ……, xn ) = gcd( xi , x2 - x1 , ……, xn - xn-1 ),必须要有一个原数 xi ...