sgu 191 Exhibition
题意:开始只有某一展台(设为A),有2种操作。1.A展台上放B产品(或者B展台放A产品)。2.A展台左边1位放B展台,左边2位放A产品。给出最终产品的排列,问能否实现。
考虑最后一个用2操作的展台,因为是最后一个用2操作的展台,它的左边2个一定是对方的。比如A展台最后要放B产品,而它左边2位都放A产品。就用栈将AAB这样的转换成B再压回栈中。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const int SZ=70010,INF=0x7FFFFFFF; void init() { } void work() { } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { char src; string str; cin>>src>>str; vector<char> stk; for(int i=0;i<str.size();++i) { stk.push_back(str[i]); for(;stk.size()>=3;) { bool bl1=stk[stk.size()-1]!=stk[stk.size()-2]; bool bl2=stk[stk.size()-1]!=stk[stk.size()-3]; if(bl1&&bl2) { stk.pop_back(),stk.pop_back(),stk.pop_back(); stk.push_back(str[i]); } else break; } } if(stk.size()==1&&stk[0]!=src)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
浙公网安备 33010602011771号