Topic Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3221
The Gordon is recently reading about a interesting game. At the beginning of the game, there are three positive numbers on a written. In each round, your 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 on the blackboard. If you decide to change the number 3 in this round, you'll delete the number 3 and the number 11=2+10-1 back T o the blackboard. So it would is 2, and one on the blackboard then. The target of this game are to reach a given number in the minimal steps.
One day, when Gordon is playing the game, his best friend Mike came. Mike saw the numbers on the blackboard were, 1967 and 1983, and asked Gordon if he had played this game from the B Eginning numbers 3, 3 and 3. Since Gordon didn ' t leave a trace on the game, who asked you, a young brilliant programmer, to help them check out if Mike Made the right guess.
Input
The ' The ' input contains an integer t (T <), indicating the number of cases. Each test case consists of the a line with six positive integers. The three are the numbers currently on Gordon's Blackboard and the last three are the numbers of that Mike guessed. It is guaranteed this every number in a game are positive and is less than 1,000,000.
Output
For the 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 7 17 1967 1983 3 3 3
Sample Output
No
Yes
Author:gao, Fei
Contest:the 9th Zhejiang University Programming Contest
Meaning
Whether the next three numbers can be transformed by one rule to the preceding three digits.
Rules:
The last three numbers can be selected each time a number is deleted, add a number to: the remaining two digits and minus one.
Ps:
We can push back from the front three digits, as long as the reverse push back equals three digits after the deletion of one of the numbers.
The code is as follows:
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace
Std
int a[4],b[4];
Long Long num[100000];
int dp[5][3];
int main () {int n,t;
cin>>t;
while (t--) {for (int i=0; i<3; i++) cin>>a[i];
for (int i=0; i<3; i++) cin>>b[i];//b-a int flag=1;
Sort (b,b+3);
DP[0][0]=B[0];
DP[0][1]=B[1];
DP[0][2]=B[2];
Qu0 dp[1][0]=b[1]+b[2]-1;
DP[1][1]=B[1];
DP[1][2]=B[2];
QU1 Dp[2][0]=b[0];
Dp[2][1]=b[0]+b[2]-1;
DP[2][2]=B[2];
Qu0 Dp[3][0]=b[0];
DP[3][1]=B[1];
Dp[3][2]=b[0]+b[1]-1;
for (int i=0; i<4; i++) sort (dp[i],dp[i]+3);
while (1) {sort (a,a+3);
for (int j=0; j<4; j) {flag=1;
for (int k=0; k<3; k++) {if (dp[j][k]!=a[k]) flag=0;
} if (flag) break;
} if (Flag==1)//pipei {puts ("Yes");
Break
} if (a[1]+1-a[0]==a[2])//Dead Loop {puts ("No");
Break
} A[2]=a[1]+1-a[0];
flag=1;
for (int j=0; j<3; j + +)/Negative number {if (a[j]<=0) flag=0;
} if (flag==0) {puts ("No");
Break
}} return 0;
}