zoukankan      html  css  js  c++  java
  • ZOJ 3180 Number Game


    Number Game

    Time Limit: 1 Second      Memory Limit: 32768 KB

    Gordon is recently reading about an interesting game. At the beginning of the game, there are three positive numbers written on a blackboard. In each round, you are asked to delete one of these three numbers. And you should write the sum of the remaining two numbers minus one back to the blackboard. For example, there are three numbers, 2, 3 and 10 on the blackboard. If you decide to change the number 3 in this round, you will delete the number 3 first and put the number 11=2+10-1 back to the blackboard. So it would be 2, 10 and 11 on the blackboard then. The target of this game is to reach a given number in the minimal steps.

    One day, when Gordon was playing the game, his best friend Mike came in. Mike saw that the numbers on the blackboard were 17, 1967 and 1983, and asked Gordon if he had played this game from the beginning numbers 3, 3 and 3. Since Gordon didn't leave a trace on the game, he asked you, a young brilliant programmer, to help them check out if Mike made the right guess.

    Input

    The first line of the input contains an integer T (T < 200), indicating the number of cases. Each test case consists of a line with six positive integers. The first three are the numbers currently on Gordon's blackboard and the last three are the numbers that Mike guessed. It is guaranteed that every number in a game is positive and is less than 1,000,000.

    Output

    For each test case, you should write a single word in a line. If it is possible to get Gordon's numbers from Mike's guess, you would give the word "Yes". Otherwise you need to output the word "No".

    Sample Input

    2
    6 10 15 7 13 26
    17 1967 1983 3 3 3

    Sample Output

    No
    Yes

    把初始状态放大一点然后倒着推。。。。

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>

    using namespace std;

    bool cmp(int a[3],int b[3])
    {
        int OK=1;
        for(int i=0;i<3;i++)
        {
            if(a!=b)
            {
                OK=0;  break;
            }
        }
        return OK;
    }

    int main()
    {
        int T;
        cin>>T;
    while(T--)
    {
        int ddp=0;
        int a[3],b[3],b1[3],b2[3],b0[3],c[3];
        cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];

        b0[0]=b[1]+b[2]-1; b0[1]=b[1]; b0[2]=b[2];
        b1[1]=b[0]+b[2]-1; b1[0]=b[0]; b1[2]=b[2];
        b2[2]=b[1]+b[0]-1; b2[1]=b[1]; b2[0]=b[0];

        sort(a,a+3);    sort(b,b+3);  sort(b0,b0+3); sort(b1,b1+3); sort(b2,b2+3);


        if(cmp(a,b)||cmp(a,b0)||cmp(a,b1)||cmp(a,b2))
        {
            ddp=1;
        }
        while(true)
        {
            for(int i=0;i<3;i++) c=a;
            if(ddp) break;
            a[2]=a[1]-a[0]+1;
            sort(a,a+3);
            if(cmp(a,b)||cmp(a,b0)||cmp(a,b1)||cmp(a,b2))
            {
                ddp=1;
            }
            if(cmp(a,c)) break;
        }

        if(ddp) puts("Yes");
        else puts("No");
    }
        return 0;
    }

  • 相关阅读:
    20201224-3
    20201224-3 列表的使用1
    20201224 字符串常用操作
    20201224-1
    20201223-1 俄罗斯方块
    3月27日:毕业设计计划
    3月26日:毕业设计计划
    3月25日:毕业设计计划
    3月24日:毕业设计计划
    3月23日:毕业设计计划
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350942.html
Copyright © 2011-2022 走看看