Topic
Ideas:
First, push backwards! To the last second step, and then:
The initial state does not necessarily satisfy this state. So we have to start from the initial state to construct the three states it departs from. Then these three states can be compared with the state of the backward push.
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;intt,a[5],b[5];intMain () {scanf ("%d",&t); while(t--) {scanf ("%d %d%d%d%d%d", &a[1],&a[2],&a[3],&b[1],&b[2],&b[3]); intok=0; Sort (a+1, A +4); Sort (b+1, B +4); intnum=0; while(a[1]+a[2]-1==a[3]){ if(a[1]==b[1]&&a[2]==b[2]&&a[3]==b[3]) {ok=1; Break;} if(a[1]==b[1]&&a[2]==b[2]&&a[3]==b[1]+b[2]-1) {ok=1; Break;} if(a[1]==b[1]&&a[2]==b[3]&&a[3]==b[1]+b[3]-1) {ok=1; Break;} if(a[1]==b[2]&&a[2]==b[3]&&a[3]==b[2]+b[3]-1) {ok=1; Break;} if(a[1]==1) Break; a[3]=a[2]-a[1]+1; Sort (a+1, A +3+1); if(a[1]<b[1]&&a[2]<b[2]&&a[3]<b[3]) Break; } if(ok==1) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
View Code
ZOJ 3180 number Game (analog, inverted)