• HDU-1297 Children’s Queue


      1 #include <bits/stdc++.h>
      2 #define pb push_back
      3 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
      4 #define INF 0x3f3f3f3f
      5 
      6 using namespace std;
      7 const int maxn = 2000;
      8 class HP
      9 {
     10     public : int len,s[maxn]; HP() {(*this) = 0;};
     11     HP(int inte) {(*this)=inte;}; HP(const char*str) {(*this)=str;};
     12     friend ostream& operator << (ostream &cout,const HP &x);
     13     HP operator = (int inte); HP operator = (const char*str);
     14     HP operator * (const HP &b);HP operator + (const HP &b);
     15     HP operator - (const HP &b);HP operator / (const HP &b);
     16     HP operator % (const HP &b);int Compare(const HP &b);
     17     bool operator < (const HP &b);
     18 };
     19 
     20 ostream& operator << (ostream &cout,const HP &x)
     21 {for(int i = x.len;i >= 1;i --) cout<<x.s[i];return cout;}
     22 
     23 HP HP::operator = (const char *str)
     24 {
     25     len = strlen(str);
     26     for(int i = 1;i <= len;i ++) s[i] = str[len-i]-'0';
     27     return (*this);
     28 }
     29 
     30 HP HP::operator = (int inte)
     31 {
     32     if(inte==0) {len = 1;s[1] = 0;return (*this);};
     33     for(len = 0;inte > 0;) {s[++len] = inte%10;inte /= 10;};
     34     return (*this);
     35 }
     36 
     37 HP HP::operator * (const HP&b)
     38 {
     39     int i,j;HP c;c.len = len+b.len;
     40     for(i = 1;i <= c.len;i ++) c.s[i] = 0;
     41     for(i = 1;i <=len;i ++) for(j = 1;j <=b.len;j ++) c.s[i+j-1]+=s[i]*b.s[j];
     42     for(i = 1;i < c.len;i ++) {c.s[i+1]+=c.s[i]/10;c.s[i]%=10;}
     43     while(c.s[i]) {c.s[i+1]=c.s[i]/10;c.s[i]%=10;i ++;}
     44     while(i>1&&!c.s[i]) i--;c.len = i;
     45     return c;
     46 }
     47 
     48 HP HP::operator+(const HP &b)
     49 {
     50     int i;HP c;c.s[1] = 0;
     51     for(i = 1;i <=len || i<=b.len || c.s[i];i ++)
     52     {
     53         if(i<=len) c.s[i]+=s[i];
     54         if(i<=b.len) c.s[i]+=b.s[i];
     55         c.s[i+1]=c.s[i]/10;c.s[i]%=10;
     56     }
     57     c.len = i-1;if(c.len==0) c.len = 1;
     58     return c;
     59 }
     60 
     61 HP HP::operator-(const HP&b)
     62 {
     63     int i, j;HP c;
     64     for(i = 1,j = 0;i <= len;i ++)
     65     {
     66         c.s[i] = s[i]-j;if(i<=b.len) c.s[i]-=b.s[i];
     67         if(c.s[i]<0){j = 1;c.s[i]+=10;}else j = 0;
     68     }
     69     c.len = len;while(c.len>1&&!c.s[c.len]) c.len--;
     70     return c;
     71 }
     72 
     73 int HP::Compare(const HP &y)
     74 {
     75     if(len>y.len) return 1;
     76     if(len<y.len) return -1;
     77     int i = len;
     78     while((i>1)&&(s[i]==y.s[i])) i--;
     79     return s[i]-y.s[i];
     80 }
     81 
     82 bool HP::operator < (const HP &y)
     83 {
     84     if(this->Compare(y)>=0)    return false;
     85     return true;
     86 }
     87 
     88 HP HP::operator / (const HP&b)
     89 {
     90     int i,j;HP d(0),c;
     91     for(i = len;i > 0;i --)
     92     {
     93         if(!(d.len==1 && d.s[1]==0))
     94             {for(j = d.len;j > 0;j --) d.s[j+1]=d.s[j];++d.len;}
     95         d.s[1] = s[i]; c.s[i] = 0;
     96         while((j = d.Compare(b))>=0)
     97             {d=d-b;c.s[i]++;if(j==0) break;}
     98     }
     99     c.len = len;while((c.len>1)&&(c.s[c.len]==0)) c.len--;
    100     return c;
    101 }
    102 
    103 HP HP::operator%(const HP&b)
    104 {
    105     int i,j;HP d(0);
    106     for(i = len;i > 0;i --)
    107     {
    108         if(!(d.len==1 && d.s[1]==0))
    109         {for(j = d.len;j > 0;j --) d.s[j+1]=d.s[j];++d.len;}
    110     d.s[1] = s[i];
    111     while((j = d.Compare(b))>=0) {d = d-b;if(j==0)break;}
    112     }
    113     return d;
    114 }
    115 
    116 HP d[maxn];
    117 HP solve(int n)
    118 {
    119     HP a = 0;
    120     if(a < d[n])
    121         return d[n];
    122     
    123     return d[n] = solve(n-1)+solve(n-2)+solve(n-4);
    124 }
    125 
    126 int main()
    127 {
    128     int N;
    129     d[1] = 1;
    130     d[2] = 2;
    131     d[3] = 4;
    132     d[4] = 7;
    133     for(int i = 4;i <= 1000;i ++)
    134         solve(i);
    135     while(~scanf("%d",&N))
    136     {
    137         cout << solve(N) << endl;
    138     }
    139     return 0; 
    140 }
  • 相关阅读:
    “智商平平”学软件
    一个多线程示例程序的BUG修复
    金旭亮《C#面向对象程序设计》2011完整版发布
    《.NET 4.0网络开发入门之旅》7:填平缓冲区陷阱
    《.NET 4.0网络开发入门之旅》5:与Socket的“再次见面”
    《.NET 4.0网络开发入门之旅》6:“麻烦”的数据缓冲区
    软件天才与技术民工
    .NET 4.0 技术亮点剖析——在中科院计算所的讲座PPT及源码下载
    C#实现程序的开机启动
    C#获取当前时间、日期
  • 原文地址:https://www.cnblogs.com/Asurudo/p/10609422.html
Copyright © 2020-2023  润新知