90分 测试点#6 RE 没用传统数组RE求助

P1255 数楼梯

dounsm @ 2022-12-29 06:42:29

记录:提交记录

我寻思着我这用STL的deque,也不会数组开小啊

求大神指导

#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <deque>

#define BIST std::string::size_type

namespace BITools{
  inline char mcton(char c){return c-'0';};
  inline char mntoc(char n){return n+'0';};

  namespace nat{
    inline bool muti_neg(bool a,bool b){
      return a^b;
    };
    template<typename T>
    inline T min(T a,T b){
      return ((a>b)?(b):(a));
    };
    template<typename T>
    inline T max(T a,T b){
      return ((a>b)?(a):(b));
    };
  };
};

class BigInt{
  public:
    std::deque<char> data;
    void _debug(){
      // for(int i=0;i<this->data.size();i++){
      //   printf("[%d]\t%c\n",i,BITools::mntoc(this->data[i]));
      // };
      for(int i=0;i<this->data.size();i++){
        putchar(BITools::mntoc(this->data[i]));
      };
      putchar('\n');
      for(int i=0;i<this->data.size();i++){
        putchar(BITools::mntoc(i));
      };
      putchar('\n');
    };
    void _clear(){
      this->data.clear();
      this->data.push_back(0);
    };
    inline int _size(void){
      return this->data.size();
    };
    BigInt(void){
      this->_clear();
    };
    template<typename T>
    BigInt(T num){
      while(num/10!=0){
        this->data.push_back(num%10);
        num=num/10;
      };
      this->data.push_back(num%10);
    };
    BigInt(const char* str){
      int ptr = 0;
      while(str[ptr]!='\0'){
        this->data.push_front(BITools::mcton(str[ptr++]));
      };
    };
    char& operator[](int i){
      return this->data[this->_size()-i-1];
    };
    void flatten(){
      char tem = 0;
      for(int i=0;i<this->_size();i++){
        tem = (this->data)[i]+tem/10;
        (this->data)[i]=tem%10;
      };
      if(tem/10!=0){
        this->data.push_back(tem/10);
      };
    };
    inline char _getEffNum(int index,int slen){
      return ((index>=slen)?(0):(this->data[index]));
    };
    inline void print(void){
      for(int i=this->data.size()-1;i>=0;i--){
        putchar(BITools::mntoc(this->data[i]));
      };
    };
    friend BigInt operator+(BigInt a,BigInt b){
      BigInt ret("0");
      ret.data.clear();
      int ale = a._size(),ble = b._size();
      int maxlen = BITools::nat::max(ale,ble);
      for(int i=0;i<maxlen;i++){
        ret.data.push_back(a._getEffNum(i,ale)+b._getEffNum(i,ble));
      };
      ret.flatten();
      return ret;
    };
};

int main(){

#ifdef LOCALTEST
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n;
  scanf("%d",&n);
  BigInt* solution = new BigInt[n+1];
  solution[0]=0;
  solution[1]=1;
  solution[2]=2;
  for(int i=3;i<=n;i++){
    solution[i]=solution[i-1]+solution[i-2];
  };
  // printf("%lld\n",solution[n]);
  solution[n].print();

  delete[] solution;
  return 0;
}

by dounsm @ 2022-12-29 07:32:42

解决了

RE不一定是数组的问题

加了一行判定:

...
  scanf("%d",&n);
  if(n==1){putchar('1');return 0;};
  BigInt* solution = new BigInt[n+1];
...

|