ZOJ 3180 number Game (analog, inverted)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.