• 高精度模板.


    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    
    const int maxn = 1000;
    
    struct bign{
        int d[maxn], len;
    
        void clean() { while(len > 1 && !d[len-1]) len--; }
    
        bign()             { memset(d, 0, sizeof(d)); len = 1; }
        bign(int num)     { *this = num; } 
        bign(char* num) { *this = num; }
        bign operator = (const char* num){
            memset(d, 0, sizeof(d)); len = strlen(num);
            for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0';
            clean();
            return *this;
        }
        bign operator = (int num){
            char s[20]; sprintf(s, "%d", num);
            *this = s;
            return *this;
        }
    
        bign operator + (const bign& b){
            bign c = *this; int i;
            for (i = 0; i < b.len; i++){
                c.d[i] += b.d[i];
                if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++;
            }
            while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++;
            c.len = max(len, b.len);
            if (c.d[i] && c.len <= i) c.len = i+1;
            return c;
        }
        bign operator - (const bign& b){
            bign c = *this; int i;
            for (i = 0; i < b.len; i++){
                c.d[i] -= b.d[i];
                if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--;
            }
            while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--;
            c.clean();
            return c;
        }
        bign operator * (const bign& b)const{
            int i, j; bign c; c.len = len + b.len; 
            for(j = 0; j < b.len; j++) 
                      for(i = 0; i < len; i++) 
                       c.d[i+j] += d[i] * b.d[j];
            for(i = 0; i < c.len-1; i++)
                c.d[i+1] += c.d[i]/10, c.d[i] %= 10;
            c.clean();
            return c;
        }
        bign operator / (const bign& b){
            int i, j;
            bign c = *this, a = 0;
            for (i = len - 1; i >= 0; i--)
            {
                a = a*10 + d[i];
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
                c.d[i] = j;
                a = a - b*j;
            }
            c.clean();
            return c;
        }
        bign operator % (const bign& b){
            int i, j;
            bign a = 0;
            for (i = len - 1; i >= 0; i--)
            {
                a = a*10 + d[i];
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
                a = a - b*j;
            }
            return a;
        }
        bign operator += (const bign& b){
            *this = *this + b;
            return *this;
        }
    
        bool operator <(const bign& b) const{
            if(len != b.len) return len < b.len;
            for(int i = len-1; i >= 0; i--)
                if(d[i] != b.d[i]) return d[i] < b.d[i];
            return false;
        }
        bool operator >(const bign& b) const{return b < *this;}
        bool operator<=(const bign& b) const{return !(b < *this);}
        bool operator>=(const bign& b) const{return !(*this < b);}
        bool operator!=(const bign& b) const{return b < *this || *this < b;}
        bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);}
    
        string str() const{
            char s[maxn]={};
            for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0';
            return s;
        }
    };
    
    istream& operator >> (istream& in, bign& x)
    {
        string s;
        in >> s;
        x = s.c_str();
        return in;
    }
    
    ostream& operator << (ostream& out, const bign& x)
    {
        out << x.str();
        return out;
    }
    int main()
    {
        freopen("noip.in","r",stdin);
        freopen("noip.out","w",stdout); 
        bign s=0,t;
        while (cin>>t)
        {
            if (t.len==1&&!t.d[0]) break;
            s=s+t;
        }
        cout<<s<<endl;
        return 0;
    }

     写了个没有/和后面运算的简单一点的。。都是自己可以理解语法

    矩阵取数游戏

    /也挺简单 但感觉noip用不到

    注意加完之后 要把剩下的10给模掉 刚开始这里写错了

    #include <bits/stdc++.h>
    using namespace std;
    #define rg register
    #define rint register int
    #define IL inline
    #define rep(i,h,t) for (int i=h;i<=t;i++)
    #define dep(i,t,h) for (int i=t;i>=h;i--)
    #define me(x) memset(x,0,sizeof(x))
    #define setit set<int>::iterator
    #define lowbit(x) (x&(-x))
    #define fi first
    #define se second
    #define mp make_pair
    #define mid ((h+t)>>1)
    #define mid2 ((h+t+1)>>1)
    #define ll long long
    char ss[1<<24],*A=ss,*B=ss;
    IL char gc()
    {
      return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;
    }
    template<class T>IL void read(T &x)
    {
      rint f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);
      while (c=gc(),c>47&&c<58) x=(x<<3)+(x<<1)+(c^48); x*=f;
    }
    char sr[1<<24],z[20]; int C=-1,Z;
    template<class T>IL void wer(T x)
    {
      if (x<0) sr[++C]='-',x=-x;
      while (z[++Z]=x%10+48,x/=10);
      while (sr[++C]=z[Z],--Z);
    }
    IL void wer1()
    {
      sr[++C]=' ';
    }
    IL void wer2()
    {
      sr[++C]='
    ';
    }
    template<class T> IL void maxa(rg T &x,rg T y)
    {
      if (x<y) x=y;
    }
    template<class T> IL void mina(rg T &x,rg T y)
    {
      if (x>y) x=y;
    }
    template<class T>IL T MAX(rg T x,rg T y)
    {
      return x>y?x:y;
    }
    template<class T>IL T MIN(rg T x,rg T y)
    {
      return x<y?x:y;
    }
    const int INF=1e9;
    struct bign{
      int d[100],len;
      IL void clear()
      {
        while (len>1&&!d[len-1]) len--;
      }
      bign()
      {
        len=1; me(d);
      }
      bign(char *c)
      {
        *this=c;
      }
      bign(int num)
      {
        *this=num;
      }
      bign operator =(const char *c)
      {
        me(d); //没有就错了 不知道为什么
        len=strlen(c);
        rep(i,0,len-1)
          d[i]=c[len-i-1]-'0';
        return *this;
      }
      bign operator =(const int num)
      {
        char s[20]={};
        sprintf(s,"%d",num);
        *this=s;
        return *this;
      }
      bign operator +(const bign c)
      {
        bign b=*this;
        int i;
        for (i=0;i<c.len;i++)
          b.d[i]+=c.d[i],b.d[i+1]+=b.d[i]/10,b.d[i]%=10;
        while (b.d[i]>9) b.d[i]%=10,i++,b.d[i]++;
        maxa(b.len,c.len);
        if (b.d[b.len]) b.len++;
        return b;
      }
      bign operator *(const bign c)
      {
        bign b;
        b.len=c.len+len;
        for (int i=0;i<c.len;i++)
          for (int j=0;j<len;j++)
            b.d[i+j]+=c.d[i]*d[j];
        for (int i=0;i<b.len;i++)
          b.d[i+1]+=b.d[i]/10,b.d[i]%=10;
        b.clear();
        return b;
      }
      bool operator <(const bign c)
      {
        if (len<c.len) return(1);
        if (len>c.len) return(0);
        for (int i=len-1;i>=0;i--)
        {
          if (d[i]<c.d[i]) return(1);
          if (d[i]>c.d[i]) return(0);
        }
      }
      string str()
      {
        char s[100]={};
        for (int i=len-1;i>=0;i--) s[i]=d[len-i-1]+'0';
        return s;
      }
    };
    bign f[100];
    int a[100];
    bign g[100][100];
    int main()
    {
      int n,m;
      read(n); read(m);
      f[0]=1;
      rep(i,1,80) f[i]=f[i-1]*2;
      bign tt=0;
      rep(i,1,n)
      {
        rep(j,1,m) read(a[j]);
        bign num=0;
        rep(j1,0,m)
          dep(j2,m+1,j1+1)
          {
            bign ans=0;
            if (j1>0) ans=g[j1-1][j2]+f[j1+m+1-j2]*a[j1];
            bign ans2=0;
            if (j2<m+1) ans2=g[j1][j2+1]+f[j1+m+1-j2]*a[j2];
            if (ans<ans2) g[j1][j2]=ans2; else g[j1][j2]=ans;
          }
       rep(j1,0,m)
         if (num<g[j1][j1+1]) num=g[j1][j1+1];    
       tt=tt+num;
      }
      cout<<tt.str()<<endl; 
      fwrite(sr,1,C+1,stdout);
      return 0;
    }
  • 相关阅读:
    暑假集训Day14 I (莫队)
    暑假集训Day14 G (gcd 数学)
    暑假集训Day13 H (进制转换 数学)
    暑假集训Day13 C (二分+贪心)
    暑假集训Day13 I (区间DP)
    暑假集训Day12 H (数论 STL)
    Java8中list转map方法总结
    Typora ---一款简洁的Markdown编辑器
    java8 map flatmap
    Elasticsearch基本查询总结
  • 原文地址:https://www.cnblogs.com/yinwuxiao/p/8442761.html
Copyright © 2020-2023  润新知