清帝之惑之乾隆

背景 Background 

         乾隆,雍正的第四子,在位60年,退位后又当了三年太上皇,终年89岁。

  乾隆即位之初,实行宽猛互济的政策,务实足国,重视农桑,停止捐纳,平定叛乱等一系列活动中,充分体现了他的文治武功,乾隆帝向慕风雅,精于骑射,笔墨留于大江南北,并是一个有名的文物收藏家。清宫书画大多是他收藏的,他在位期间编纂的《四库全书》共收书3503种,79337卷,36304册,其卷数是《永乐大典》的三倍,成为我国古代思想文化遗产的总汇。

  乾隆好游江南,喜欢江南的山水,喜欢江南的人文,喜欢江南的才气,同时他也喜欢江南的汉族美女。

描述 Description  

         话说乾隆带着他的宰相刘罗锅和你出巡江南,被杭州城府邀请去听戏,至于什么戏,那就不知了。乾隆很高兴,撒酒与君臣共享。三更欲回住处,可是乾隆这人挺怪,他首先要到西湖边散散步,而且命令不准有人跟着他。

  小醉,步于西湖岸,停于断桥前,突闻琴声悠悠,歌儿婉婉。这乐曲不哀伤不愁怅,少了一分怨女的羁绊,多了一分少女的期盼。乾隆走上前去,视其背影,为一女子手抚古琴,悠悠而唱。可是这么晚了,小女怎么还不回家呢,莫非是她起早床?乾隆走上前去,小声问道:“伊为何未宿?”,小女沉默片刻,转身而来。顿时,顿时,顿时!!!!!乾隆惊呆了!!!!哇!!!!噻!!!!!!这人,这伊!!!!原来!!!!!!!不是一个美女(狂汗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 <= 250.

  此时的你,已经是皇帝身边的小太监,自然有必要为皇上解决此题。

输入格式 Input Format

         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.

输出格式 Output Format    

        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.

 

 

 

高精度运算。

 1 #include<iostream>
 2 #include<string.h> 
 3 //#include<fstream> 
 4 using namespace std;
 5 //ifstream fin("cin.in"); 
 6 
 7 string s;
 8 int n,a[400000],b[400000],c[400000],l,len; 
 9 
10 void Count(){
11      int i,j,len1=len; 
12      int t=n; 
13 
14      while(t>1)
15      {
16        t--; 
17        memset(c,0,sizeof(c));
18        for(i=0;i<=len;++i)
19        for(j=0;j<=len1;++j)
20        {
21          c[i+j]+=a[i]*b[j]; 
22          if(c[i+j]>=10)
23          {
24            c[i+j+1]+=c[i+j]/10;
25            c[i+j]%=10;               
26                        } 
27                } 
28 
29        i=len+len1+5;
30        while(c[i]==0)
31        i--; 
32         
33        len=i;
34        for(i=0;i<=len;++i)
35        a[i]=c[i];     
36                } 
37      } 
38 
39 void Print(){
40      int i,j; 
41      l*=n;
42      for(i=0;i<l;++i)
43      b[i]=a[i];
44      i=len+5,j=0;
45      while(a[i]==0) i--; 
46      for(i;i>=l;--i)
47      cout<<a[i];
48      while(b[j]==0) j++; 
49      if(j<=l-1) 
50      cout<<".";
51      for(i=l-1;i>=j;--i)
52      cout<<b[i];
53      cout<<endl;
54      } 
55 
56 int main()
57 {
58     while(cin>>s>>n)
59     {
60       if(n==0) {cout<<1<<endl;continue;} 
61       memset(b,0,sizeof(b));
62       memset(a,0,sizeof(a)); 
63       int i,j=0; 
64       for(i=0;i<s.size();++i)
65       if(s[i]!='.')  b[j++]=s[i]-'0';
66       else l=s.size()-i-1;
67       
68       j--; 
69       for(i=0;i<=j;++i)
70       a[i]=b[j-i];
71       
72       for(i=0;i<=j;++i)
73       b[i]=a[i];
74       
75       len=j; 
76       
77       Count(); 
78       
79       Print();                      
80                     } 
81     return 0; 
82     } 
posted on 2012-08-04 20:49  怡红公子  阅读(426)  评论(0编辑  收藏  举报