码迷,mamicode.com
首页 > 其他好文 > 详细

vijos P1200

时间:2016-11-08 07:58:43      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:进制   ems   style   技术   精度   pre   iostream   pac   namespace   

技术分享

技术分享

 

 1 #include <iostream>
 2 #include <cmath>
 3 #include <string.h>
 4 using namespace std;
 5 
 6 typedef int atype[3000];
 7 
 8 void gaocheng(atype &a ,atype b)
 9 {
10   atype c;
11   memset(c,0,sizeof(c));
12 
13 
14   for (int i = 0; i <= 2999; i++)
15   {
16     for (int j = 0; j <= 2999-i; j++)
17     {
18       c[j+i]=c[j+i]+a[j]*b[i];
19     }
20   }
21 
22  for (int i = 0; i <= 2998; i++)
23  {
24    c[i+1]=c[i+1] + int(c[i]/10);
25    c[i]=c[i] % 10;
26  }
27  c[2999]=c[2999] % 10;
28 
29 for (int i = 0; i <= 2999; i++){a[i]=c[i];}
30 
31 }
32 
33 
34 
35 
36 int main()
37 {
38   
39   atype x,z;
40   memset(x,0,sizeof(x));
41   memset(z,0,sizeof(z));
42 
43   x[0]=1;
44   z[0]=2;
45 
46 
47   int n;
48   cin>>n;
49 
50   if(n==0 ||n==1){cout<<1<<F;return 0;}
51   if(n==2){cout<<2<<T;return 0;}
52 
53 
54 
55   for(int i=0; i<=n-2; i++)
56   {
57     gaocheng(x,z);
58     z[0]++;
59   }
60 
61 long long sum;
62 sum=0;
63 for(int i=0; i<=2999; i++)
64 {
65  sum=sum+x[i];
66 }
67 
68 cout<<sum;
69 
70 
71 if(n>=3){cout<<F;}
72 else{cout<<T;}
73 
74 
75 return 0;
76 }

 

 

TF是不需要一个个算的,3以后都是3的倍数,3的倍数各位的和依然是3的倍数,所以后面全是F


这里高精度只需要 一个数组跟一个int相乘就好,我的高精度程序是数组跟数组相乘,导致非常慢,
另外 感觉10000进制应该也是一种优化吧

 

vijos P1200

标签:进制   ems   style   技术   精度   pre   iostream   pac   namespace   

原文地址:http://www.cnblogs.com/Ro0kie/p/6041340.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!