[tem]高精度1

 1 //倒着存 B取的低精最大值所以简化了一点
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <algorithm>
 7 using namespace std;
 8 const int N=1005,B=1e4,W=4,L=1005;
 9 struct people{
10     int a,b,t;
11 }p[N];
12 bool cmp(people x,people y){
13     return x.t<y.t;
14 }
15 
16 struct big{
17     int size,d[L];
18     big(int a=1):size(a){memset(d,0,sizeof(int)*L);}
19     
20 };
21 bool bigger(big &a,big &b){
22     if(a.size>b.size) return true;
23     if(a.size<b.size) return false;
24     for(int i=a.size-1;i>=0;i++){
25         if(a.d[i]>b.d[i]) return true;
26     }
27     return false;
28 }
29 bool noSmallInt(big &a,int k){    //special
30     if(a.size>1) return true;
31     if(a.d[0]>=k) return true;
32     return false;
33 }
34 void clear0(big &a){
35     a.size=1;
36     memset(a.d,0,sizeof(int)*L);
37 }
38 void copy(big &t,big &s){
39     t.size=s.size;
40     memcpy(t.d,s.d,sizeof(int)*L);
41 }
42 
43 void chengInt(big &a,int k){
44     int g=0,i;
45     for(i=0;i<a.size;i++){
46         int tmp=a.d[i]*k;
47         a.d[i]=(tmp+g)%B;
48         g=(tmp+g)/B;
49     }
50     while(g){
51         a.d[i++]=g%B; a.size++;
52         g/=B;
53     }
54 }
55 
56 void jianInt(big &a,int k){
57     if(a.d[0]<k){
58         int i=1;a.d[0]+=B;
59         while(a.d[i]==0) {a.d[i]+=B;i++;}
60         a.d[i]--;
61         while(i==a.size-1&&a.d[i]==0) a.size--,i--;
62     }
63     a.d[0]-=k;
64 }
65 
66 void addInt(big &a,int k){
67     int g,i=0,tmp=a.d[0]+k;
68     a.d[0]=tmp%B;
69     g=tmp/B;
70     while(g){
71         tmp=a.d[++i]+g;
72         a.d[i]=tmp%B; if(i>a.size-1) a.size=i+1;
73         g=tmp/B;
74     }
75 }
76 
77 void chuInt(big &a,int k){
78     int g=0;
79     for(int i=a.size-1;i>=0;i--){
80         g=g*B+a.d[i];
81         a.d[i]=g/k;
82         g%=k;
83     }
84     while(a.d[a.size-1]==0) a.size--;
85 }

 

posted @ 2016-08-08 23:35  Candy?  阅读(332)  评论(0编辑  收藏  举报