oj1262 question: Three---First is an integer T (T<=24), and then there are T groups of test data, each group of data includes four integers, occupying two rows, indicating the initial layout of the board

oj1262 Question: Three

Original title

Insert picture description here

Analysis and code

I didn’t understand this question at
first, but I understood it under the guidance of another student. Let me write down the general idea after I understand it: First of all, we can’t see the pictures here, but we learned from sample lnput and sample output You can know that the target interface is:
Insert picture description here
Then understand the meaning of the question, roughly the position of 0 is equivalent to an empty position, and the adjacent position can be moved to this empty position, just like Huarong Road.
Because there are many situations, we can move 0 uniformly to the same position, and then make a judgment, and since only adjacent positions can be moved, we might as well set an array The
Insert picture description here
above figure is the position of i in data[i], and then use A for loop moves 0 to the position of data[3], and then discusses the relative positions of data[0], data[1], and data[2] to determine the position.
Insert picture description here
There are three situations in the
Insert picture description here
following figure: the following code:

#include<iostream>
using namespace std;
int main()
{
    
    
    int num[4];
    int n;
    cin >> n;
    while(n--) 
    {
    
    
        cin>>num[0]>>num[1]>>num[3]>>num[2];
        for (int i=0; i<3; i++) 
        {
    
    
            if (num[i]==0) 
            {
    
    
                num[i] = num[i+1];
                num[i+1] = 0;
            }
        }
        int sum = num[0]*100+num[1]*10+num[2];
        if (sum==123||sum==231||sum==312)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

If it helps you, you might as well give it a thumbs up!

Guess you like

Origin blog.csdn.net/Freedom_cao/article/details/108437916