观察样例得知就是和离’_’左边最近的’w’交换位置,然后和离’_’右边最近的’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>#include<bitset>#define mkp make_pairusingnamespace std;constdouble EPS=1e-;typedeflonglong lon;const lon SZ=,INF=0x7FFFFFFF,mod=;void work(string str,string tmp,int n){ vector<int> res;int pos=str.find(_);for(int time=;;++time){if(str==tmp)break;for(int i=;i<min(time,n);++i){if(str==tmp)break;int dst;if(time&)dst=str.find_last_of(w,pos);else dst=str.find(b,pos);if(dst==-)break;//cout<<str<<endl;//cout<<dst<<endl; res.push_back(dst); swap(str[pos],str[dst]); pos=dst;}}for(int i=;i<res.size();++i){if(i%!=)cout<<” “; cout<<res[i]+;if((i+)%==)cout<<endl;}cout<<endl;}int main(){ std::ios::sync_with_stdio();//freopen(“d:\\1.txt”,”r”,stdin); lon casenum;//cin>>casenum;//for(lon time=1;time<=casenum;++time){int n; cin>>n;string str(n,w); str+=_; str+=string(n,b);string tmp(n,b); tmp+=_; tmp+=string(n,w); work(str,tmp,n);}return;}

发表回复

后才能评论