50%的数据满足:1<=n<=5
100%的数据满足:1<=n<=50
在纸上画画发现,
Txxxx4: Txxxx1 Txxxx2 Txxxx3
TxxxxK: T..1 T..2 T..3 (可能没有)
flag表示当前方向是否连通
#include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define ForkD(i,k,n) for(int i=n;i>=k;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (o<<1) #define Rson ((o<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define pb push_back #define mp make_pair #define MAXN (50+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} char s[MAXN]; void pri(int len,int x) { putchar('T'); Rep(i,len) printf("%c",s[i]); printf("%d\n",x); } bool flag[10]={0}; int main() { // freopen("bzoj1258.in","r",stdin); // freopen(".out","w",stdout); scanf("T%s",s); int n=strlen(s); if (s[n-1]=='4') { For(i,3) pri(n-1,i); return 0; } flag[s[n-1]-'0']=1; pri(n-1,4); RepD(i,n-2) { if (!flag[s[i]-'0']) { flag[s[i]-'0']=1; pri(i,4); } } return 0; }