Exercises
Construction problem ... At that time thought of how to do it.
Helpless code force is too weak, a position to write the wrong FST
The concrete idea is. As long as the same letter is not adjacent, it is possible to construct
The specific construction method is to put the same letter of this paragraph on the far right
XXXXXXXXX-----
XXXXXXXXXX----
As shown, then the X is drawn in circles.
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intmaxn=200100;Const intmod=1e9+7;Const intinf=1e9;vector<int> v[ -];strings;inta[ -];intMain () {CIN>>s; for(intI=0;i< -; i++) v[s[i]-'A'].PB (i); intflag=0, Pos,pre; for(intI=0;i< -; i++) { if(V[i].size () <=1)Continue; for(intj=1; J<v[i].size (); j + +) { if(v[i][j]-v[i][j-1]!=1) {flag=1; Pre=v[i][j-1]; POS=V[i][j]; Break; } } } if(!flag) cout<<"Impossible"<<Endl; Else { intk=pos-Pre; if(k%2) {k/=2; K++; for(intI= --k+1; i<= -; i++) a[i]=pre++; K--; for(intI= -; i>= --k+1; i--) a[i]=pre++; intj= --K; for(j= --k;j>= -; j--) { ++POS; if(pos> -) Break; A[J]=POS; } if(pos> -) { intm=0; if(j>= -) { while(j>= -) a[j--]=m++; } J=1; while(j< --K) a[j++]=m++; } Else if(j< -) {J=1; POS++; while(pos<= -) a[j++]=pos++; intm=0; while(j< --K) a[j++]=m++; } } Else{k/=2; for(intI= --k+1; i<= -; i++) a[i]=pre++; for(intI= -; i>= --k+1; i--) a[i]=pre++; intj= --K; for(j= --k;j>= -; j--) { ++POS; if(pos> -) Break; A[J]=POS; } if(pos> -) { intm=0; if(j>= -) { while(j>= -) a[j--]=m++; } J=1; while(j<= --K) a[j++]=m++; } Else if(j< -) {J=1; POS++; while(pos<= -) a[j++]=pos++; intm=0; while(j<= --K) a[j++]=m++; } } for(intI=1; i<= -; i++) cout<<S[a[i]]; cout<<Endl; for(intI= -; i<= -; i++) cout<<S[a[i]]; cout<<Endl; } return 0;}
Canada Cup C. Hidden Word