问题 H: 乾隆巡江南

时间限制: 2 Sec  内存限制: 128 MB
提交: 13  解决: 3
[提交][状态][讨论版]

题目描述

话说乾隆带着他的宰相刘罗锅和你出巡江南,被杭州城府邀请去听戏,至于什么戏,那就不知了。乾隆很高兴,撒酒与君臣共享。三更欲回住处,可是乾隆这人挺怪,他首先要到西湖边散散步,而且命令不准有人跟着他。         小醉,步于西湖岸,停于断桥前,突闻琴声悠悠,歌儿婉婉。这乐曲不哀伤不愁怅,少了一分怨女的羁绊,多了一分少女的期盼。乾隆走上前去,视其背影,为一女子手抚古琴,悠悠而唱。可是这么晚了,小女怎么还不回家呢,莫非是她起早床?乾隆走上前去,小声问道:“伊为何未宿?”,小女沉默片刻,转身而来。顿时,顿时,顿时!!!!!乾隆惊呆了!!!!哇!!!!噻!!!!!!这人,这伊!!!!原来!!!!!!!不是一个美女(狂汗ing)。小女并未回答她的话,只是与乾隆侃了侃诗。乾隆兴哉,问其曰:“不知偶能助伊否?”,小女曰:“偶无所以助,且有一事相求,愿君能解之。”         乾隆一看,立刻晕到在地,片刻而起,曰:“明日必解之”,且去。         回到家中,乾隆夜召你“入寝”,曰:“如此姑娘,如此情调,如此罗曼蒂克,竟然丢一个如此煞风景之问”,一边发气,一边把这个问题交给你。你一看,顿然发现,原来是用蝌蚪文写的:         Problems  involving  the  computation  of  exact  values  of  very  large  magnitude  and  precision  are  common.  For  example,  the  computation  of  the  national  debt  is  a  taxing  experience  for  many  computer  systems.          This  problem  requires  that  you  write  a  program  to  compute  the  exact  value  of  Rn  where  R  is  a  real  number  (  0.0  <   R  < =  9999.9)  and  n  is  an  integer  such  that  0  <   n  < =  200.          此时的你,已经是皇帝身边的小太监,自然有必要为皇上解决此题。

输入

The  input  will  consist  of  a  set  (less  than  11)  of  pairs  of  values  for  R  and  n.  The  R  value  will  occupy  columns  1  through  6,  and  the  n  value  will  be  in  columns  8  and  9.

输出

The  output  will  consist  of  one  line  for  each  line  of  input  giving  the  exact  value  of  R^n.  Leading  zeros  should  be  suppressed  in  the  output.  Insignificant  trailing  zeros  must  not  be  printed.  Don't  print  the  decimal  point  if  the  result  is  an  integer.

样例输入

95.123  2
0.4321 5
5.1234 7
6.7592 3
98.999 5
1.0100 10

样例输出

9048.385129
.01506334182914325601
92663.3181348508776705891407804544
308.806114738688
9509420210.697891990494999
1.10462212541120451001 题目意思就是说,算R的n次方,整数部分全是零的话不要输出0(如例2),小数最后的0也不用输出来,例如0.100只需输出.1即可,若答案是整数,不用输出小数点
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
char a1[];
int a[];
int b[];
int c[];
int n;
while (cin >> a1 >> n)
{
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(c, , sizeof(c));
int l = strlen(a1);
int k=-, j, i;//k一开始初始化为-1,为了辨别输进来的是小数还是整数
for (i = ; i < l; i++)
{
if (a1[i] == '.')
{//是小数的话,先把"."去了
k = i;
for (j = i; j < l; j++)
{
a1[j] = a1[j + ];//小数点后的几位都向前移一位
}
k = l - k - ;//k用来标记第几位应该有小数
break;
}
}
if (k != -)
{//输进来是小数的话
for (i = ; i <= l - ; i++)
{
a[l - - i] = a1[i] - '';
b[l - - i] = a1[i] - '';
}
l--;
}
else
{//是整数的话
for (i = ; i <= l - ; i++)
{
a[l - i] = a1[i] - '';//倒的存入a数组
b[l - i] = a1[i] - '';
}
} int lc = l;
int x;
int nn = n - ;
while (nn--)
{
for (i = ; i <= l; i++)//这里是l
{
x = ;
for (j = ; j <= lc; j++)//这里是lc,别弄反了,一开始我就反了
{//乘法运算
c[i + j - ] = a[i] * b[j] + x + c[i + j - ];//当前位=乘机+进的位+当前位
x = c[i + j - ] / ;
c[i + j - ] = c[i + j - ] % ;
}
c[lc + i] = x;
}
lc = l + lc;
for (i = ; i <= lc; i++)
{
b[i] = c[i];
}
memset(c, , sizeof(c));
}
if (k == -)
{//整数的情况
while (b[lc] == && lc>) lc--;//删除前导零
for (i = lc; i >= ; i--) cout << b[i];
cout << endl;
}
else
{//小数的情况 bool f = ;
for (i = lc; i >= n * k + ; i--)//n*k这个位置要放‘.’
{//先输出整数部分
if (b[i] == && f == ) continue;
else if (b[i] != ) { f = ; cout << b[i]; }
else cout << b[i];
}
f = ;
int pp = ;
for (i = ; i <= n * k; i++)
{
if (b[i] == && f == ) continue;
else if (b[i] != && f == ) { f = ; pp = i; break; }
}
if (i != n * k + )//i==n*k+1时,代表小数位全是0,不需要输出‘.’
{
cout << ".";
for (i = n * k; i >= pp; i--) cout << b[i];
}
cout << endl;
}
}
return ;
}
 

高精度算r的n次方 问题 H: 乾隆巡江南的更多相关文章

  1. 洛谷 P1045 麦森数 (快速幂+高精度+算位数骚操作)

    这道题太精彩了! 我一开始想直接一波暴力算,然后叫上去只有50分,50分超时 然后我改成万位制提高运算效率,还是只有50分 然后我丧心病狂开long long用10的10次方作为一位,也就是100亿进 ...

  2. A - 高精度(大数)N次方(第二季水)

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  3. Attrib +s +a +h +r 隐藏文件原理与破解

    制作了一个PE启动盘,不过这个启动盘不能深度隐藏,否则没效果,可以又想不让别人看见PE启动盘的一些内容,防止别人误删或者修改,于是就想找一种可以隐藏文件的方法,普通的隐藏文件的方法如下:

  4. 【高精度】NCPC 2014 C catalansqure

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789 题目大意: 求大卡特兰数..公式如下.输入n求Sn(n<=5000) 题目 ...

  5. 1001. Exponentiation高精度运算总结

    解题思路 这道题属于高精度乘法运算,要求输入一个实数R一个指数N,求实数R的N次方,由于R有5个数位,而N又特别大,因此用C++自带的数据类型放不下. 解题思路是通过数组储存每次乘积结果和底数的每一位 ...

  6. 高精度POJ1001

    今天看到这道题了 poj1001 题目地址是http://bailian.openjudge.cn/practice/1001/ 英文看得懂,可是算法不明白,所以转别人的文章,留着给学生看看:乔高建( ...

  7. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  8. Poj.Grids 2951 浮点数求高精度幂

    2951:浮点数求高精度幂 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方. ...

  9. 求高精度幂(java)

    求高精度幂 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...

随机推荐

  1. 【HDOJ1018】【大数阶乘位数】【斯特林公式】

    http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)     ...

  2. C++ 作业(哈夫曼树)

    #include<bits/stdc++.h> #define fi first #define se second #define int long long using namespa ...

  3. jsp中引入jquery报错:Failed to load resource: the server responded with a status of 404 (Not Found)

    问题描述: 今天自己在搭建spring.springMVC.hibernate框架,搭建完成后,在引入jquery时,发现jquery不管用.我的解决顺序是: 1.检查路径,发现路径没错,另外需要注意 ...

  4. string的方法find

    官方解释:find(sub[, start[, end]]) Return the lowest index in the string where substring sub is found wi ...

  5. LeetCode – Smallest Rotation with Highest Score

    Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], A[K+1 ...

  6. 【maven】maven源码打包

    1.打包时附加外部Jar包 <!--编译+外部 Jar打包-->          <plugin>            <artifactId>maven-co ...

  7. Redis和MySQL的结合方案

    转载:http://m.blog.csdn.net/article/details?id=50586990 方案一: 程序同时写Redis和MySQL读Redis 方案二: 程序写MySQL, 使用G ...

  8. apache kafka系列之在zookeeper中存储结构

    1.topic注册信息 /brokers/topics/[topic] : 存储某个topic的partitions所有分配信息 Schema:   {    "version": ...

  9. 如何对 PHP 代码加密?

    这几天有同事问如何对 PHP 代码进行加密? 在我印象中 PHP 加密还是比较麻烦的,之前只知道 Zend Guard . 刚刚找了一圈发现现在还是有很多可行的方案,先记录一下,以后使用. 使用混淆 ...

  10. centos7下yum安装mariadb

    1.安装MariaDB 删除已安装的mysqlyum remove mysql mysql-server mysql-libs mysql-devel删除存放数据的目录rm -rf /var/lib/ ...