问题 H: 乾隆巡江南
时间限制: 2 Sec 内存限制: 128 MB提交: 15 解决: 4
[ 提交][ 状态][ 讨论版]
题目描述
话说乾隆带着他的宰相刘罗锅和你出巡江南,被杭州城府邀请去听戏,至于什么戏,那就不知了。乾隆很高兴,撒酒与君臣共享。三更欲回住处,可是乾隆这人挺怪,他首先要到西湖边散散步,而且命令不准有人跟着他。 小醉,步于西湖岸,停于断桥前,突闻琴声悠悠,歌儿婉婉。这乐曲不哀伤不愁怅,少了一分怨女的羁绊,多了一分少女的期盼。乾隆走上前去,视其背影,为一女子手抚古琴,悠悠而唱。可是这么晚了,小女怎么还不回家呢,莫非是她起早床?乾隆走上前去,小声问道:“伊为何未宿?”,小女沉默片刻,转身而来。顿时,顿时,顿时!!!!!乾隆惊呆了!!!!哇!!!!噻!!!!!!这人,这伊!!!!原来!!!!!!!不是一个美女(狂汗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.6978919904949991.10462212541120451001
#include<iostream> #include<string.h> #include<algorithm> #include<functional> #include<cstdio> #include<queue> #include<map> #include<stack> #include<string.h> #include<string> char t1[6003]; int r[6003][2],t[6003]; int n; using namespace std; int main() { while(scanf("%s%d",&t1,&n)!=EOF) { if(n==0) { printf("1"); printf("\n"); continue; } memset(r,0,sizeof(r)); memset(t,0,sizeof(t)); int ll,L=strlen(t1); int i,j,aa,bb; for(i=0; i<L; i++) if(t1[i]=='.') break; int dec=-1; if(i!=L)//判断是否为小数 { for(j=i; j<L-1; j++) t1[j]=t1[j+1];//小数转为整数 dec=(L-i-1)*n;运算后小数的位数 L--; aa=i,bb=L-aa; } else aa=L,bb=0; aa=n*aa,bb=n*bb;//整数位数aa,小数位数bb for(i=1; i<=L; i++) { t[i]=t1[L-i]-'0'; r[i][0]=t[i]; } int d=0,x1=0; n--; for(int k=1;k<=n;k++) { for(i=0; i<=6*(k+1); i++) r[i][d^1]=0;//滚动数组 for(i=1; i<=6; i++)//基数最大为六位 { x1=0; for(j=1; j<=6*(k+1); j++)//乘一次最多加六位 { r[i+j-1][d^1]=t[i]*r[j][d]+x1+r[i+j-1][d^1]; x1=r[i+j-1][d^1]/10; r[i+j-1][d^1]%=10; } } d=d^1;数组滚动 } int x=1,y=3000; while(r[x][d]==0&&x<=bb)//删除小数部分的后导0 x++; while(r[y][d]==0&&y>bb)//删除整数部分的前导0 y--; if(dec==-1)//若原来为整数则直接输出 { for(i=y; i>=x; i--) printf("%d",r[i][d]); printf("\n"); continue; } int L2=y; if(dec>=y) printf(".");若整数部分为零,直接输"." int T=L2-dec,z=0; for(i=y; i>=x; i--) { z++; printf("%d",r[i][d]); if(z==T&&L2>dec&&x<=bb)printf("."); } printf("\n"); } return 0; }