Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3221
Gordon is recently reading on an interesting game. At the beginning of the game, there is three positive numbers written on a blackboard. In each round, you is asked to delete one of these three numbers. And you should write the sum of the remaining, numbers minus one back to the blackboard. For example, there is three numbers, 2, 3 and ten on the blackboard. If you decide to change the number 3 in this round, you'll delete the number 3 first and put the number 11=2+10-1 back T o the blackboard. So it would is 2, and the blackboard then. The target of this game was to reach a given number in the minimal steps.
One day, when Gordon was playing the game, he best friend Mike came in. Mike saw that the numbers in 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, 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 < a), indicating the number of cases. Each test case consists of a line with six positive integers. The first three is the numbers currently on Gordon's Blackboard and the last three is the numbers that Mike guessed. It is guaranteed this every number in a game is positive and was less than 1,000,000.
Output
For the test case, you should write a single word with 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
Author:GAO, Fei
Contest:The 9th Zhejiang University programming Contest
Test instructions
Ask back three numbers can be converted to the previous three numbers by a rule!
Rules:
The last three numbers can be selected each time a number is deleted, add a number: The remaining two numbers and minus one!
Ps:
We can from the front three numbers, the inverse pushes back, as long as the inverse pushes back is equal to the next three numbers to delete one of the numbers after the situation can!
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;}
ZOJ 3180 number Game (math AH)