Posted on 2008-12-10 23:06
Hero 阅读(112)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1206 C++ Accepted 0.031 209 KB
2
3 //其实只要两个数加起来不能有进位就行了
4
5 //按位考虑排列组合--只有最左边那一位有36种可能--其他有55中可能
6
7 #include <iostream>
8 using namespace std;
9
10 const int Base=1000000000;
11 const int Capacity=1000;
12 typedef long long llong;
13 struct BigInt{
14 int Len;
15 int Data[Capacity];
16 BigInt():Len(0){}
17 BigInt(const BigInt &V):Len(V.Len){memcpy(Data,V.Data,Len*sizeof*Data);}
18 BigInt(int V):Len(0){for(;V>0;V/=Base) Data[Len++]=V%Base;}
19 BigInt &operator=(const BigInt &V){Len=V.Len;memcpy(Data,V.Data,Len*sizeof*Data);return *this;}
20 int &operator[](int Index){return Data[Index];}
21 int operator[](int Index)const{return Data[Index];}
22 };
23 int compare(const BigInt &A,const BigInt &B){
24 if(A.Len!=B.Len) return A.Len>B.Len ? 1:-1;
25 int i;
26 for(i=A.Len-1;i>=0 && A[i]==B[i];i--);
27 if(i<0)return 0;
28 return A[i]>B[i] ? 1:-1;
29 }
30 BigInt operator+(const BigInt &A,const BigInt &B){
31 int i,Carry(0);
32 BigInt R;
33 for(i=0;i<A.Len||i<B.Len||Carry>0;i++){
34 if(i<A.Len) Carry+=A[i];
35 if(i<B.Len) Carry+=B[i];;
36 R[i]=Carry%Base;
37 Carry/=Base;
38 }
39 R.Len=i;
40 return R;
41 }
42 BigInt operator-(const BigInt &A,const BigInt &B){
43 int i,Carry(0);
44 BigInt R;
45 R.Len=A.Len;
46 for(i=0;i<R.Len;i++){
47 R[i]=A[i]-Carry;
48 if(i<B.Len) R[i]-=B[i];
49 if(R[i]<0) Carry=1,R[i]+=Base;
50 else Carry=0;
51 }
52 while(R.Len>0&&R[R.Len-1]==0) R.Len--;
53 return R;
54 }
55 BigInt operator*(const BigInt &A,const int &B){
56 int i;
57 llong Carry(0);
58 BigInt R;
59 for(i=0;i<A.Len||Carry>0;i++){
60 if(i<A.Len) Carry+=llong(A[i])*B;
61 R[i]=Carry%Base;
62 Carry/=Base;
63 }
64 R.Len=i;
65 return R;
66 }
67 istream &operator>>(istream &In,BigInt &V){
68 char Ch;
69 for(V=0;In>>Ch;){
70 V=V*10+(Ch-'0');
71 if(In.peek()<=' ') break;
72 }
73 return In;
74 }
75 ostream &operator<<(ostream &Out,const BigInt &V){
76 int i;
77 Out<<(V.Len==0 ? 0:V[V.Len-1]);
78 for(i=V.Len-2;i>=0;i--) for(int j=Base/10;j>0;j/=10) Out<<V[i]/j%10;
79 return Out;
80 }
81 BigInt Bint0(0) ;
82 BigInt Bint1(1) ;
83
84 int inn ;
85
86 int main()
87 {
88 while( scanf( "%d", &inn ) != EOF )
89 {
90 BigInt out = Bint1 ;
91
92 out = out * ( (1+8)*8/2 ) ;
93 int temp = 55 ;
94
95 for( int i=2; i<=inn; i++ ) out = out * temp ;
96
97 cout << out << endl ;
98 }
99
100 return 0 ;
101 }