Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1258
If the last one is 4, it would be better to change to 123.
Then the last one is not 4, at most three answers, then you can find that the last one to change to 4 of the string will certainly have. It can then be found that 1 inherits its ancestor 12, 2 inherits 13, 3 inherits 23, and then sweeps it again.
(the mouth is so much still to find the law, tat
#include <cstring>#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineMAXN 2000using namespacestd;intn,f[4];CharS[MAXN];intRead () {intx=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}void out() {Putchar ('T'); Rep (I,1, N-1) Putchar (S[i]); Puts ("4");}intMain () {//freopen ("In.txt", "R", stdin);scanf"%s", s); N=strlen (s)-1; if(s[n]=='4') {Rep (I,1,3) {Putchar ('T'); Rep (J,1, N-1) Putchar (S[j]); printf ("%d\n", i); } return 0; } if(s[n]=='1') f[1]=f[3]=1; if(s[n]=='2') f[1]=f[2]=1; if(s[n]=='3') f[2]=f[3]=1; out(); while(--N) { intx=s[n]-'0'; if(x==1) { if(f[2]) f[2]=0, out(); } if(x==2){ if(f[3]) f[3]=0, out(); } if(x==3){ if(f[1]) f[1]=0, out(); } } return 0;}
BZOJ1258: [CQOI2007] Triangle Tri