zoj 3180 Number Game

来源:互联网 发布:什么拍照软件有虚化 编辑:程序博客网 时间:2024/05/03 00:10
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

26 10 15 7 13 2617 1967 1983 3 3 3

Sample Output

NoYes


代码:

#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;int e[3],s[3];int tmp1[3],tmp2[3],tmp3[3];bool check(){    int i;    for(i=0;i<3;i++)    {        if(e[i]!=tmp1[i])        break;    }    if(i==3)    return true;    for(i=0;i<3;i++)    {        if(e[i]!=tmp2[i])        break;    }    if(i==3)    return true;    for(i=0;i<3;i++)    {        if(e[i]!=tmp3[i])        break;    }    if(i==3)    return true;    return false;}int main(){    int T;    scanf("%d",&T);    while(T--)    {        scanf("%d%d%d%d%d%d",&e[0],&e[1],&e[2],&s[0],&s[1],&s[2]);        tmp1[0]=s[0],tmp1[1]=s[1],tmp1[2]=s[0]+s[1]-1;sort(tmp1,tmp1+3);        tmp2[0]=s[0],tmp2[1]=s[2],tmp2[2]=s[0]+s[2]-1;sort(tmp2,tmp2+3);        tmp3[0]=s[1],tmp3[1]=s[2],tmp3[2]=s[1]+s[2]-1;sort(tmp3,tmp3+3);        sort(s,s+3);        while(true)        {            sort(e,e+3);            if(check())            {                printf("Yes\n");                break;            }            else if(e[0]<s[0])            {                printf("No\n");                break;            }            else            {                e[0]=e[0];                e[1]=e[1];                e[2]=e[1]+1-e[0];            }        }    }    return 0;}


原创粉丝点击