首页 > 其他 > 详细

洛谷p3952

时间:2019-07-18 17:14:50      阅读:88      评论:0      收藏:0      [点我收藏+]

  技术分享图片

 

技术分享图片

 终于跨过这个坑,没啥好说的,只是纪念一下

#include<bits/stdc++.h>
using namespace std;

bool xSy(string s);

int main(){
  int t, l, w, max;
  bool flag;
  string giveCplx, realCplx, temp2, temp3;
  stack<string> s;
  vector<char> values;
  char temp[100];

  cin >> t;
  while(t--){
    cin >> l >> giveCplx;
    getchar();
    w = 0;
    max = 0;
    flag = true;
    values.clear();
    realCplx = "";
    temp2 = temp3 = "";
    while(!s.empty())
      s.pop();

    while(l--){
      gets(temp);
      // cout << temp << endl;
      if(temp[0] == F){
        if(w != 0){
          w += s.size();
          if(w > max)
            max = w;
          w = 0;
        }
        s.push(temp);
        values.clear();
      }else if(temp[0] == E){
        if(s.empty()){
          flag = false;
        }
        else{
          temp2 = s.top();
          s.pop();
        }

        if( find(values.begin(), values.end(), temp2[2]) != values.end() ){
          flag = false;
          // cout << temp2[5] << endl;
        }else{
          if( xSy(temp2) ){
            if( temp2[temp2.size()-1] == n && temp2[4] != n )
              w++;
            values.push_back(temp2[2]);
          }else{
            // values.clear();
            w = 0;
          }
        }
      }

    }

    if(w > max)
      max = w;

    if(!s.empty())
      flag = false;

    if(flag){
      if(max == 0){
        realCplx += "O(1)";
      }else{
        realCplx += "O(n^";
        while(max != 0){
          temp3 += max%10 + 0;
          max /= 10;
        }
        for(int i=temp3.size()-1; i>=0; i--)
          realCplx += temp3[i];
        realCplx += ")";
      }
      // cout << realCplx << endl;
      if(realCplx == giveCplx)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }else{
      cout << "ERR" << endl;
    }

  }
  return 0;
}

bool xSy(string s){
  int i, j;
  int a, b, c;
  a = b = 0;
  c = 1;

  if(s[s.size()-1] == n){
    return true;
  }else{
    for(i=s.size()-1; i>=0; i--){
      if(s[i] ==  )
        break;
      a += (s[i]-0) * c;
      c *= 10;
    }
    c = 1;
    for(j=i-1; j>=0; j--){
      if(s[j] ==  )
        break;
      if(s[j] == n && s[s.size()-1] != n){
        return false;
      }
      b += (s[j]-0) * c;
      c *= 10;
    }

    if( a < b )
      return false;
    else
      return true;
  }
}

 

洛谷p3952

原文:https://www.cnblogs.com/ssNiper/p/11208448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!