首页 > 代码库 > vijosP1779国王游戏

vijosP1779国王游戏

题目:https://vijos.org/p/1779

题解:忽然想起来我好像还没写过高精度除以单精度,于是拿这题练练手。。。没想到1A了。。。

代码:

  1 #include<cstdio>  2 #include<cstdlib>  3 #include<cmath>  4 #include<cstring>  5 #include<algorithm>  6 #include<iostream>  7 #include<string>  8 #include<set>  9 #include<map> 10 #include<vector> 11 #include<queue> 12 #define maxn (5000+10) 13 #define for0(i,n) for(int i=0;i<=n;i++) 14 #define for1(i,n) for(int i=1;i<=n;i++) 15 #define for2(i,s,t) for(int i=s;i<=t;i++) 16 #define for3(i,t,s) for(int i=t;i>=s;i--) 17 #define ll long long 18 #define mod 10000 19 using namespace std; 20 inline int read() 21 { 22   int x=0,f=1;char ch=getchar(); 23   while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();} 24   while(ch>=0&&ch<=9){x=10*x+ch-0;ch=getchar();} 25   return x*f; 26 } 27 class bigg 28 { 29     public: 30         int c[maxn],l; 31         bigg(){memset(c,0,sizeof(c));l=0;} 32         bigg operator = (int b) 33         { 34             memset(c,0,sizeof(c));l=0; 35             while(b)c[++l]=b%mod,b/=mod; 36             return(*this); 37         } 38         bigg operator =(const bigg &b) 39         { 40             l=b.l; 41             for1(i,l)c[i]=b.c[i]; 42             return(*this); 43         } 44         bigg operator +(const bigg &b) 45         { 46             bigg a; 47             a.l=max(l,b.l); 48             for1(i,l) 49              { 50               a.c[i]+=a.l+b.l; 51               a.c[i+1]=a.c[i]/mod; 52               a.c[i]%=mod; 53              } 54             if(c[a.l+1])a.l++;  55             return  a; 56         } 57         bigg operator *(int b) 58         { 59             bigg a;a.l=l; 60             int x=0; 61             for1(i,l) 62             { 63                 x+=b*c[i]; 64                 a.c[i]=x%mod; 65                 x/=mod; 66             } 67             while(x)a.c[++a.l]=x%mod,x/=mod; 68             return a; 69         } 70         bigg operator /(int b) 71         { 72             bigg a; 73             int x=0; 74             for3(i,l,1) 75             { 76                 x=x*mod+c[i]; 77                 a.c[i]=x/b; 78                 x%=b; 79             } 80             a.l=l; 81             while(!a.c[a.l])a.l--; 82             return a; 83         } 84         void print() 85         { 86             printf("%d",c[l]); 87             for3(i,l-1,1)printf("%04d",c[i]);printf("\n"); 88         } 89 }; 90 int n,a[maxn],b[maxn],c[maxn]; 91 inline bool cmp(int x,int y){return a[x]*b[x]<a[y]*b[y];} 92 int main() 93 { 94     freopen("input.txt","r",stdin); 95     freopen("output.txt","w",stdout); 96     n=read()+1; 97     for1(i,n)a[i]=read(),b[i]=read(),c[i]=i; 98     sort(c+1,c+n+1,cmp); 99     bigg ans;ans=1;100     for1(i,n-1)ans=ans*a[c[i]];101     ans=ans/b[c[n]];102     ans.print();103     return 0;104 }
View Code

 

vijosP1779国王游戏